SCJP Certification

Sun Certified Java Programmer Certification exam essentials

August 15th, 2011

What is contructor overloading?

No Comments, Uncategorized, by Daisy Williams.

Constructor overloading is a technique in Java in which a class can have any number of constructors that differ in parameter lists. A constructor uses its arguments to initialize the new object’s state. The compiler differentiates these constructors by taking into account the number of parameters in the list and their types.

As constructors are not members of a class, they are not inherited by subclasses. Therefore, each of the subclasses must specifically implement any constructors it needs. However, a subclass can use the constructors of its superclass by using the super keyword.

Share

August 13th, 2011

What is the Console class?

No Comments, Uncategorized, by Daisy Williams.

The Console class extends the Object class and has convenience methods to read from and write to the console objects. Also, it has the readPassword() method to read a password from the console. If the underlying virtual machine has a console, it can be obtained by invoking the System.console() method. If no console device is available, then an invocation of the System.console() method returns null.

Share

August 8th, 2011

What is the readPassword() method?

No Comments, Uncategorized, by Daisy Williams.

The readPassword() method of the Console class is used to read a password from the underlying console. This method does not read any line-termination character. It returns null if an end of stream has been reached. There are two syntaxes for the readPassword() method as follows:

public char[] readPassword(): This method is used to read passwords from a console with echoing enabled.

public char[] readPassword(String fmt, Object… args): This method is used to read passwords from a console with echoing enabled in the given format.

Share

August 8th, 2011

What are the data type conversions available in Java?

No Comments, Uncategorized, by Daisy Williams.

Java provides two kinds of data type conversions, namely automatic and explicit. Automatic conversion takes place when the following two conditions are fulfilled:

  • The two types are compatible.
  • The destination type is larger than the source type.

When these two conditions are met, widening conversion takes place, i.e., a narrow data type is promoted to a wider one. For example, the value of byte type will be promoted to int, as int is wider than byte in width. However, in many cases, an automatic conversion cannot be performed. For example, an automatic conversion cannot be performed to convert int to byte, as int is wider than byte. In such cases, conversion is performed explicitly. The general form to perform such type of narrowing conversion is as follows:

(target-type) value

Share