[20 Jan 2012 | 3 Comments | 2,087 views]

String class provides many constructors to create a new String object from character array, byte array, StringBuffer, StringBuilder, etc.

String()Creates an empty string.
String(String)Creates a string from the specified string.
String(char[])Creates a string from an

Read more…

[20 Jan 2012 | 2 Comments | 1,986 views]
  • Strings are objects in Java.
  • Just like creating other objects, you can create an instance of a String with the new keyword, like this,
  • But since we will use Strings all the time, the most direct way to create a

Read more…

[20 Jan 2012 | No Comment | 671 views]

Strings can be constructed a variety of ways.

  • Direct method
  • Using String class constructors
  • Using toString() method defined in java.lang.Object

These are explained in detail in the following sections. Read more…

[20 Jan 2012 | No Comment | 1,471 views]
  • String represents combinations of character literals that are enclosed in double quotes, i.e.) any character(s) inside double quotess
  • Each character in a string is a 16-bit Unicode character, to provide a rich, international set of characters.
  • The String class is

Read more…

[18 Jan 2012 | No Comment | 238 views]
  1. Static keyword can be applied to instance variable, instance method and inner classes.
  2. There is only one copy of static variable and all objects share them.
  3. Static variables are loaded and initialized when the class is loaded.
  4. The output of

Read more…

[18 Jan 2012 | No Comment | 261 views]
  • Static members from superclass are not inherited to the sub class.
  • Static methods cannot be overridden in the subclass.
  • Same method can be redefined in the subclass, thus hiding the superclass method


We are trying to invoke Read more…

[18 Jan 2012 | 2 Comments | 455 views]
  • Static keyword can be applied to a block, { }, and they become static initialization block which runs only once when the class is first loaded by the JVM.
  • This is used for initializing all the static variables and to

Read more…

[18 Jan 2012 | No Comment | 239 views]
  • To access instance variable/ method we use dot operator on the reference variable of the class. For example, to access the name instance variable of Student class, we create a reference variable and use it to access it.
  • Similarly

Read more…

[18 Jan 2012 | No Comment | 284 views]
  • If you have a requirement where the method’s behavior is independent of the state of the object then you go for static method.
  • Static methods have several restrictions:

    They can only invoke other static methods.

  • Static methods can only access

Read more…

[18 Jan 2012 | One Comment | 483 views]
  • Only instance variable can be marked with static keyword.
  • Syntax: static variable declaration
  • static data_type variableName;
    Where, is optional.

  • Parameter and local variable cannot be marked with static variable.
  • There is only one copy of the static variable (also known

Read more…