Java Reference Index

  1. Introduction
  2. Data Types
  3. Arrays
  4. Operators
  5. Program Control
  6. Classes
  7. Objects
  8. Interfaces
  9. Containers
  10. Class Structure
  11. Error Handling

    Program Types

  12. Applications
  13. Applets

    How To

  14. Type Conversions


  15. java.lang.reflect
  16. java.applet
  17. java.awt
  18. java.beans
  20. java.lang
  21. java.math
  23. java.rm
  26. java.text
  27. java.util
  28. java.servlet


  29. Object Class


  30. Terms
  31. Credits


Object Creation

String teamName = new String(); 
Random randInfo = new Random(); 
Jabberwock j = new Jabberwock(); 

"Several things happen when you use the new operator: The new instance of the given class is created, memory is allocated for it, and a special method defined in the given class is called. This special method is called a constructor."

Referring to Object Variables

"For example, if you have an object assigned to the variable myCustomer and that object has a variable called orderTotal, you refer to that variable’s value like this:


" The dot method is used to refer to object variables, class variables, and methods.

Class Variables

"Class variables, as you learned, are variables that are defined and stored in the class itself. Their values apply to the class and all of its instances. You define class variables by including the static keyword before the variable itself. For example, take the following partial class definition:"

class FamilyMember { 
    static String surname = “Igwebuike”; 
    String name; 
    int age; 

"To access class variables, you use the same dot notation used with instance variables."

Object Comparison

Using the "==" operator to test two objects for equality, tests to see if the objects are the same object. This does not test for object value equality. Testing two string values is done with statements like:

String str1, str2; 
str1 = “Free the bound periodicals.”; 
str2 = str1;
boolean Equal = str1.equals(str2));