Tips and Study Notes for Sun Certified Java2 Programmer's Exam



Section 4 Language Fundamentals


Structure of source files:


Variable Declarations and Identifiers:
Rules:



Consider this:

public class TestClass 
{
  public static void main(String[] args)
  {
    System.out.println("Hello, World!");
  }
}
Points to remember:


Three Important points:

Example:
class TestClass 
{
  int   i; //initialized to 0
  float f; //initialized to 0.0
  boolean bool; //initialized to false 

  int[] iA;     //initialized to null: S.o.p(iA) will print 'null'
                //S.o.p(iA[0]) will throw NullPointerException

  String[] sA;  //initialized to null: S.o.p(sA) will print 'null'


  public void m1() //to see about local variables
  {
    int k; //WILL NOT BE INITIALIZED. S.o.p (k); ERROR, k is not initialized! 

    int[] jA; //WILL NOT BE INITIALIZED. S.o.p (jA); ERROR, jA is not initialized! 

    int[] kA = new int[3]; //elements are initialized automatically to { 0, 0, 0} because default value of int is 0 

    String[] sA = new String[3]; //elements are initialized automatically to { null, null, null} because default value of Object is null. 

  }

}


Range of primitives:
boolean : true/false
byte (8 bits => 2^8 values) : -128 to 127 (-2^7 to 2^7 -1)
short (16 bits => 2^16 values) : -32768 to 32767 (-2^15 to 2^15 -1)
char  (16 bits => 2^16 values) :  0 to 65536 (0 to 2^16 -1)
int (32 bits => 2^32 values) :     -2^31 to 2^31 -1
long (64 bits => 2^64 values) : -2^63 to 2^63 -1
float 32 bits
double 32 bits

.3e2 is a valid float but e2 is not. e2 is parsed as a variable name.

Octal numbers are written by prepending 0 in front of the no. Eg. 012 is 12 in octal.
Hex numbers are written by prepending 0x in front of the no. Eg. 0x12 is 12 in hex.

Read following links to understand how the conversions from Binary to octal to decimal to hex are done. Conversions of float and double are way out of scope. Don't worry about them.

 http://www.belmont.cc.oh.us/dews/stupro/stupro13/stupro13.htm

 http://www.tpub.com/neets/book13/53j.htm

 http://www.danbbs.dk/~erikoest/hex.htm  OR  http://www.danbbs.dk/~erikoest/octal.htm

 http://www2.gasou.edu/student/gsi23996/RHelp/binary.html