Explore BrainMass

Write a user-defined class called Person.

1. What is the difference between a Java compiler and a Java interpreter?

2. Write a user-defined class called Person. This class should have private instance variables defined as:

private int age;private String firstName;private String lastName;
In addition, the class should have a constructor defined as:

public Person(String _firstName, String _lastName, int _age)
that assigns values to the private instance variables. The class should also include the following public methods:

public void printName() - prints the person's namepublic void printAge() - prints the person's agepublic void printAgeGroup() - prints the person's age group (i.e. 20's. 30's, etc.)
Only include this last method if it is necessary to include logic in the assignment.

Write a second class with the method, "public static void main(String args[])". At least two objects based on the Person class should be created in the "main" method. The name, age, and age group should be displayed for each object.

3. Pick a problematic situation that you think a Java program can solve or make easier. Explain the problem and then write the pseudo code for it.

Solution Preview

1. Java compiler is a program which translates Java language source code into the Java Virtual Machine (JVM) bytecodes. Java interpreter is a program which implements the JVM specification and actually executes the bytecodes (and thereby running your program).

2. See attached.

3. One area is the creation of threads. Thread application is a very important part of programming. However, other languages such as C++ is not very easy to create and manage threads. Compared to these languages, Java make creating and mangement of threads much easier. Here is a sample code:

public class SimpleThreads {

//Display a message, preceded by the name of the current thread
static void threadMessage(String message) {
String ...

Solution Summary

What is the difference between a Java compiler and a Java interpreter?