Tuesday, July 12, 2011

What is the difference between JDK and JRE?


What is the difference between JDK and JRE?
The JRE is the Java RunTime Environment that is a plug-in needed for running java programs. The JRE is an implementation of the Java Virtual Machine which actually executes Java programs.
The JDK is the Java Development Kit for Java application developers. The JDK is bundle of software which contains one (or more) JRE's along with the various development tools like the Java source compilers, bundling and deployment tools, debuggers, development libraries, etc.

Spring Tutorial


Spring interview question: http://www.developersbook.com/

http://static.springsource.org/docs/Spring-MVC-step-by-step/overview.html#overview-whats-covered

http://java9s.com/

http://www.theserverside.com/news/1364527/Introduction-to-the-Spring-Framework




String pool in java

public class DemoStringCreation {

  public static void main (String args[]) {
    String str1 = "Hello"; 
    String str2 = "Hello";
    System.out.println("str1 and str2 are created by using string literal.");   
    System.out.println("    str1 == str2 is " + (str1 == str2)); 
    System.out.println("    str1.equals(str2) is " + str1.equals(str2)); 

   
    String str3 = new String("Hello"); 
    String str4 = new String("Hello");
    System.out.println("str3 and str4 are created by using new operator.");   
    System.out.println("    str3 == str4 is " + (str3 == str4)); 
    System.out.println("    str3.equals(str4) is " + str3.equals(str4)); 
   
    String str5 = "Hel"+ "lo"; 
    String str6 = "He" + "llo";
    System.out.println("str5 and str6 are created by using string
constant expression.");   
    System.out.println("    str5 == str6 is " + (str5 == str6)); 
    System.out.println("    str5.equals(str6) is " + str5.equals(str6));

    String s = "lo";
    String str7 = "Hel"+ s; 
    String str8 = "He" + "llo";
    System.out.println("str7 is computed at runtime.");          
    System.out.println("str8 is created by using string constant
expression.");   
    System.out.println("    str7 == str8 is " + (str7 == str8)); 
    System.out.println("    str7.equals(str8) is " + str7.equals(str8));
   
  }
}
The output result is:
str1 and str2 are created by using string literal.
    str1 == str2 is true
    str1.equals(str2) is true
str3 and str4 are created by using new operator.
    str3 == str4 is false
    str3.equals(str4) is true
str5 and str6 are created by using string constant expression.
    str5 == str6 is true
    str5.equals(str6) is true
str7 is computed at runtime.
str8 is created by using string constant expression.
    str7 == str8 is false
    str7.equals(str8) is true
The creation of two strings with the same sequence of letters without the use of the new keyword will create pointers to the same String in the Java String literal pool. The String literal pool is a way Java conserves resources.

REF: