Tips For Sun Certification

Access modifiers for instance variables and methods
a. public
b. private
c. protected
d. none (default / package)
Access modifiers for classes
a. public
b. none
Modifiers for classes, methods and instance variables
a. abstract
b. final
a. abstract
b. final
c. native
d. synchronized
e. static
Instance Variables
a. final
b. static
c. transient
d. volatile
Local variables
The only allowed modifier is final. Otherwise none.

A table of information on integer data types

TYPE       BITS     BYTES       RANGE              CAPACITY
byte       8        1           -2^7 to (2^7)-1    2^8
short      8x2      2          -2^15 to (2^15)-1   2^16
int        8x4      4          -2^31 to (2^31)-1   2^32
long       8x8      8          -2^63 to (2^63)-1   2^64
char       8x2      2           0 to 2^16-1        2^16

Tip: An int type can hold 4 bytes. That is 4×8=32 bits.
Can range from minus 2 to the power (32-1) TO 2 to the power (32-1) minus 1.
Capacity: -2^31 to (2^31)-1 is exactly 2 to the power 32 values including the 0.

Allowed implicit assignments for Integer Types


For example a byte can be assigned to a short implicitly without giving a compile time error.
A char and a short can both be safely assigned to an int type. And so forth.


o A class with abstract methods must itself be declared abstract.

o A static method can only access static instance members (members denote methods, instance variables, inner classes).

Scope or Visibility of methods

diff class    diff class/   extended class extended class
/same package /diff package /same package /diff package
private      X                X              X             X
default     YES               X              YES           X
protected   YES               X              YES          YES
public      YES              YES             YES          YES

private ->default ->protected ->public
· Automatic variables (local variables) are not initialized by the system; every automatic variable must be explicitly initialized before being used. Otherwise a compile time error occurs.
· Final arrays itself cannot change their original reference but all the elements of the array can be assigned new values.
· Reading may be informative, but the inquisitive mind seeks practical answers. So there is no other way to crack the certification than getting your hands dirty with code. And try to avoid using an IDE.
If class greenheads extends class vegetable and class vegetable extends class food and class food extends class eatable; and class meat extends class food then we have the following scenario:
Vegetable and meat both extend eatable as well as food. And greenheads extend vegetable, food and eatable; meat extends both food and eatable.

When an object is cast to something that is not its original class type, a class cast exception occurs.
The compiler will not let you make a cast if there is no chance for the cast to succeed.
Suppose you have an array of Employee objects called staff[] that includes a couple of Manager objects that extends Employee, and you have an unrelated class called Cat.

Cat bert= (Cat) staff[i]; // will give a compile time error
Manager boss= (Manager)staff[i];//will compile fine
//but will give a runtime error when staff[i] is just Employee

In this case ClassCastException) occurs if staff[i] does not happen to be a Manager object.
All runtime errors are unchecked.
Checked exceptions and unchecked exceptions inherit from class Exception.
Exception class and errors inherit from Throwable. Checked exceptions have to be caught or declared else the code will not compile. Unchecked exceptions can be caught with a catch clause but it is not imperative to do so. They will cause a program to terminate if not caught. Run time exceptions usually represent program bugs. Programmers can however throw a run time exception under specific conditions and then catch them to perform some other activity.

· instanceof operator returns true if the object is an instance of the named class or any of its subclasses.
· None of the components inside a loop construct are compulsory


is perfectly legal and executes an infinite loop.
· Any number type may be compared with another number type. For instance a float may be compared with an int type.
· Strings that have the same value at compile time, share the same memory space and hence when compared with == will return true. (== checks whether the storage locations are same, in case of objects).
· Strings that are created at run time do not share the same memory and the test with == will return false.
· The switch construct can only accept data types that can be converted to int. Going by the discussion at the beginning of this post, that includes byte, short, char and int itself.

String java= “Java”
String va= “va”;
if(java==(“Ja”+va))//returns false
{//this is a runtime check
if(java== “Ja”+ “va”)//returns true
{//this is a compile time check

The nuances of inheritance
If class Child inherits from class Parent and both Parent and Child have methods called bawl() and instance variables called temper then :

Parent p = new Child();//Child is the father of man?

p.bawl() will invoke the bawl() in the Child class
p.temper will be the value of temper in the Parent class.

A funny expression
Will the following piece of code compile?

int i=1;do while(i!=0){}while(i>1);

On further observation the above expression can be expanded into

//at least one execution being do while loop
//might not execute even once being while loop

Overloading and Overriding
Overloaded methods have the same method name but a different parameter list. (different signature) They may or may not have the same return type.
Overridden methods on the other hand have same name, same parameter list and same return type.(Signature+return type)
· The overridden method must have the same or more accessibility than the parent method.
· It must throw the same or subset of the exceptions thrown by the parent method.

Math functions
sqrt(0.0) returns 0.0
sqrt(-1) returns NaN or the java equivalent of NotANumber

· All sorted collections begin with Tree
· All mapped collections begin with Map and use keys
· HashMap is a non synchronized Hashtable
· ArrayList is a non synchronized Vector
· Maps allow duplicates and use a key
Summary on Collections

Non duplicating , Unordered SET
Duplicating, Ordered LIST
Duplicating, Ordered with Keys MAP

Non Duplicating, Sorted SORTEDSET -TreeSet
Duplicating, Sorted, with Keys SORTEDMAP -TreeMap

Concrete classes that implement the LIST interface includes ArrayList.
A List is an duplicating, ordered Collection
A Vector is similar to an ArrayList, except that it is synchronized.

Concrete classes that implement SET include HashSet
A HashSet is a non-duplicating, unordered collection..

Concrete classes that implement the SORTED SET interface include TreeSet.
A TreeSet is a non-duplicating, ordered collection that contains unique elements.

Concrete classes that implement the MAP interface include HashMap
A HashMap is a duplicating, unordered collection that contains key value pairs.
A Hashtable is similar to a HashMap except that it is synchronized and does not allow null values.

HashSet allows only one null key, but HashMap can allow one null key + multiple null values. A HashSet is implemented in terms of a HashMap. It’s a mapping between the key and PRESENT object.

Concerte classs that implement the SORTED MAP interface include TreeMap
A TreeMap is a duplicating, ordered collection that contains key value pairs. Keys must be unique.

About cuppajavamattiz
Matty Jacob - Avid technical blogger with interests in J2EE, Web Application Servers, Web frameworks, Open source libraries, Relational Databases, Web Services, Source control repositories, ETL, IDE Tools and related technologies.

Comments are closed.

%d bloggers like this: