SCJP Certification

Sun Certified Java Programmer Certification exam essentials

September 15th, 2011

What are static variables?

No Comments, Java Facts, by Daisy Williams.

Variables that have only one copy per class are known as static variables. They are not attached to a particular instance of a class but rather belong to a class as a whole. They are declared by using the static keyword as a modifier. For example:

static type varIdentifier;

where, the name of the variable is varIdentifier and its data type is specified by type.

Static variables that are not explicitly initialized in the code are automatically initialized with a default value. The default value depends on the data type of the variables. The table given below shows the default values:

Data Type Initial Value
boolean false
byte 0
short 0
int 0
long 0L
char ‘u0000′
float 0.0F
double 0.0D
Object reference null
Share

September 11th, 2011

What is a default constructor?

No Comments, Java Facts, by Daisy Williams.

A constructor without any parameters is known as a default constructor. When a class is defined without any constructor, the Java compiler provides an implicit default constructor. The implicit default constructor is equivalent to the following implementation:

class name(){
super();
}

When the implicit default constructor of a class is invoked, it implicitly calls the no parameter constructor in the superclass. This action taken by a default constructor ensures that the inherited state of the object is initialized properly. In addition, it initializes all the instance variables in the object to the default value depending on their data type.

The default constructor of a class has the same access modifier with which the class has been declared. For example, the default constructor of a public class is implicitly given the public access. The default constructor of a protected class is implicitly given the protected access. The default constructor of a private class is implicitly given the private access. Otherwise, the default constructor has the default access implied by no access modifier.

Share

September 8th, 2011

What symbols are used to represent modifiers in UML?

No Comments, Java Facts, by Daisy Williams.

UML uses various types of graphical notations to represent different relationships, operations, and attributes. In UML, each modifier is represented by a symbol, as shown in the table below:

Modifiers Symbol
Public methods or classes +
Private methods, elements, or classes -
Protected methods, elements, or variables #
Static methods, elements, or variables Underlined
Share

September 5th, 2011

What is multiplicity?

No Comments, Java Facts, by Daisy Williams.

The multiplicity of a relationship between two classes defines the number of objects of one class in relation to the number of objects of another class. In UML, the multiplicity of zero to many is represented by an asterisk(*) symbol. A one to many relationship is represented by using the 1..* notation. The following table describes the common multiplicities:

Multiplicity Representation
Exactly one instance 1
Zero or more instances 0..* or *
One or more instances 1..*
No instances or one instance 0..1
Share