Java Reference
In-Depth Information
Notice that both class files were generated even though we only saved Employee. Well, isn't RAD helpful?! Not only
does RAD perform the compilation of Employee for us but because EmployeeApp creates (instantiates) an Employee
object, RAD also creates the Employee.class file. Because EmployeeApp “depends” on Employee, in Java-speak, the
classes are said to have a dependency relationship. This is just another example of the great help RAD provides.
Results of the Tutorial
Here's what we now have:
1.
In myFirstPackage, one new file called Employee.java.
2.
The executable source code in Employee should look like the following:
package myFirstPackage;
public class Employee {
public String empName = new String();
public Employee(String name) {
empName = name;
this .displayName();
}
private void displayName() {
System. out .println(empName);
}
}
3.
The executable source code in EmployeeApp should look like the following:
package myFirstPackage;
public class EmployeeApp {
public static void main(String[] args) {
Employee emp = new Employee("Mary Worker");
}
}
Review Questions
1.
What is the function of the JVM?
2.
Which are executable: java files, class files, or both?
3.
What is a method signature?
4.
What is the purpose of a jar file?
5.
How does RAD indicate source code errors?
6.
Explain the differences between perspectives.
7.
What is the relationship between source code, machine language, and bytecode.
Review Exercise
In this exercise, a new Java class called Shipment will be created. Shipment will accept information about a shipment
being received and will have a method to display this information. ShipmentApp will be modified to instantiate an
object of type Shipment, assign the object to a variable named shipObj, and invoke Shipment object's display method.
 
Search WWH ::




Custom Search