Thursday, 29 January 2015

Java Version Changes history

Java Version Changes history 


The Java language has undergone several changes since JDK 1.0 as well as numerous additions of classes and packages to the standard library. Since J2SE 1.4, the evolution of the Java language has been governed by the Java Community Process (JCP), which uses Java Specification Requests (JSRs) to propose and specify additions and changes to the Java platform. The language is specified by the Java Language Specification (JLS); changes to the JLS are managed under JSR 901



In addition to the language changes, much more dramatic changes have been made to the Java Class Library over the years, which has grown from a few hundred classes in JDK 1.0 to over three thousand in J2SE 5. Entire new APIs, such as Swing and Java2D, have been introduced, and many of the original JDK 1.0 classes and methods have been deprecated. Some programs allow conversion of Java programs from one version of the Java platform to an older one (for example Java 5.0 backported to 1.4) (see Java backporting tools).


1  JDK Alpha and Beta (1995)
2  JDK 1.0 (January 23, 1996)
3  JDK 1.1 (February 19, 1997)
4  J2SE 1.2 (December 8, 1998)
5  J2SE 1.3 (May 8, 2000)
6  J2SE 1.4 (February 6, 2002)
7  J2SE 5.0 (September 30, 2004)
8  Java SE 6 (December 11, 2006)
8. 1 Java 6 updates
9  Java SE 7 (July 28, 2011)
9. 1 Java 7 updates
10  Java SE 8 (March 18, 2014)
10. 1 Java 8 updates
11  Java SE 9

12  Java SE 10



JDK 1.0 (January 23, 1996)

Originally called Oak. Initial release The first stable version, JDK 1.0.2, is called Java 1.

Note : In versions of Java and the JDK up to 1.0.1, private and protected keywords could be used together to create yet another form of protection that would restrict access to methods or variables solely to subclasses of a given class. As of 1.0.2, this capability has been removed from the language.


JDK 1.1 (February 19, 1997)

Major additions included:

an extensive retooling of the AWT event model
inner classes added to the language
JavaBeans
JDBC
RMI
reflection which supported Introspection only, no modification at runtime was possible.
JIT(Just In Time) compiler on Microsoft Windows platforms, produced for JavaSoft by Symantec

J2SE 1.2 (December 8, 1998)

Codename Playground. This and subsequent releases through J2SE 5.0 were rebranded retrospectively Java 2 and the version name "J2SE" (Java 2 Platform, Standard Edition) replaced JDK to distinguish the base platform from J2EE (Java 2 Platform, Enterprise Edition) and J2ME (Java 2 Platform, Micro Edition). This was a very significant release of Java as it tripled the size of the Java platform to 1520 classes in 59 packages. Major additions included:

strictfp keyword
the Swing graphical API was integrated into the core classes
Sun's JVM was equipped with a JIT compiler for the first time
Java plug-in
Java IDL, an IDL implementation for CORBA interoperability
Collections framework

J2SE 1.3 (May 8, 2000)

Codename Kestrel. The most notable changes were:

HotSpot JVM included (the HotSpot JVM was first released in April 1999 for the J2SE 1.2 JVM)
RMI was modified to support optional compatibility with CORBA
Java Naming and Directory Interface (JNDI) included in core libraries (previously available as an extension)
Java Platform Debugger Architecture (JPDA)
JavaSound
Synthetic proxy classes

J2SE 1.4 (February 6, 2002)
Codename Merlin. This was the first release of the Java platform developed under the Java Community Process as JSR 59. Major changes included:

Language changes

assert keyword (Specified in JSR 41.)
Library improvements
regular expressions modeled after Perl regular expressions
exception chaining allows an exception to encapsulate original lower-level exception
Internet Protocol version 6 (IPv6) support
non-blocking IO (named New Input/Output, NIO) (Specified in JSR 51.)
logging API (Specified in JSR 47.)
image I/O API for reading and writing images in formats like JPEG and PNG
integrated XML parser and XSLT processor (JAXP) (Specified in JSR 5 and JSR 63.)
integrated security and cryptography extensions (JCE, JSSE, JAAS)
Java Web Start included (Java Web Start was first released in March 2001 for J2SE 1.3) (Specified in JSR 56.)
Preferences API (java.util.prefs)
Support and security updates for Java 1.4 ended in October 2008.

J2SE 5.0 (September 30, 2004)

Codename Tiger. Originally numbered 1.5, which is still used as the internal version number. The number was changed to "better reflect the level of maturity, stability, scalability and security of the J2SE. This version was developed under JSR 176.

J2SE 5.0 entered its end-of-public-updates period on April 8, 2008; updates are no longer available to the public as of November 3, 2009. Updates were available to Oracle Customers until May 2014.

Tiger added a number of significant new language features:

Generics: Provides compile-time (static) type safety for collections and eliminates the need for most typecasts (type conversion). (Specified by JSR 14.)

Metadata: Also called annotations; allows language constructs such as classes and methods to be tagged with additional data, which can then be processed by metadata-aware utilities. (Specified by JSR 175.)

Autoboxing/unboxing: Automatic conversions between primitive types (such as int) and primitive wrapper classes (such as Integer). (Specified by JSR 201.)

Enumerations: The enum keyword creates a typesafe, ordered list of values (such as Day.MONDAY, Day.TUESDAY, etc.). Previously this could only be achieved by non-typesafe constant integers or manually constructed classes (typesafe enum pattern). (Specified by JSR 201.)

Varargs: The last parameter of a method can now be declared using a type name followed by three dots (e.g. void drawtext(String... lines)). In the calling code any number of parameters of that type can be used and they are then placed in an array to be passed to the method, or alternatively the calling code can pass an array of that type.

Enhanced for each loop: The for loop syntax is extended with special syntax for iterating over each member of either an array or any Iterable, such as the standard Collection classes. (Specified by JSR 201.)

Fix the previously broken semantics of the Java Memory Model, which defines how threads interact through memory.

Static imports

There were also the following improvements to the standard libraries:

Automatic stub generation for RMI objects.

Swing: New skinnable look and feel, called synth.

The concurrency utilities in package java.util.concurrent.

Scanner class for parsing data from various input streams and buffers.

Java 5 is the last release of Java to officially support the Microsoft Windows 9x line (Windows 95, Windows 98, Windows ME), while Windows Vista is the newest version of Windows that J2SE 5 was supported on prior to Java 5 going end of life in October 2009.

Java 5 Update 5 (1.5.0_05) is the last release of Java to work without any problems on Windows NT 4.0.

Java 5 is the default version of Java installed on Apple Mac OS X 10.5 (Leopard). Java 6 can be installed and set as the default to be used on 64-bit (Core 2 Duo and higher) processor machines. Java 6 is also supported by 32-bit machines running Mac OS X 10.6 (Snow Leopard).

Java SE 6 (December 11, 2006)

Codename Mustang. As of this version, Sun replaced the name "J2SE" with Java SE and dropped the ".0" from the version number. Internal numbering for developers remains 1.6.0. This version was developed under JSR 270.

During the development phase, new builds including enhancements and bug fixes were released approximately weekly. Beta versions were released in February and June 2006, leading up to a final release that occurred on December 11, 2006.

Major changes included in this version:

Support for older Win9x versions dropped; unofficially, Java 6 Update 7 was the last release of Java shown to work on these versions of Windows.[citation needed] This is believed[by whom?] to be due to the major changes in Update 10.

Scripting Language Support (JSR 223): Generic API for tight integration with scripting languages, and built-in Mozilla JavaScript Rhino integration

Dramatic performance improvements for the core platform, and Swing.

Improved Web Service support through JAX-WS (JSR 224)

JDBC 4.0 support (JSR 221).

Java Compiler API (JSR 199): an API allowing a Java program to select and invoke a Java Compiler programmatically.

Upgrade of JAXB to version 2.0: Including integration of a StAX parser.

Support for pluggable annotations (JSR 269)

Many GUI improvements, such as integration of SwingWorker in the API, table sorting and filtering, and true Swing double-buffering (eliminating the gray-area effect).

JVM improvements include: synchronization and compiler performance optimizations, new algorithms and upgrades to existing garbage collection algorithms, and application start-up performance.


Java 6 reached the end of its supported life in February 2013, at which time all public updates, including security updates, were scheduled to be stopped.Oracle released one more update to Java 6 in March 2013, which patched some security vulnerabilities.


Java SE 7 (July 28, 2011)

Java 7 (codename Dolphin) is a major update that was launched on July 7, 2011 and was made available for developers on July 28, 2011.[96] The development period was organized into thirteen milestones; on June 6, 2011, the last of the thirteen milestones was finished. On average, 8 builds (which generally included enhancements and bug fixes) were released per milestone. The feature list at the OpenJDK 7 project lists many of the changes.

Additions in Java 7 include:

JVM support for dynamic languages, with the new invokedynamic bytecode under JSR-292,
following the prototyping work currently done on the Multi Language Virtual Machine

Compressed 64-bit pointers (available in Java 6 with -XX:+UseCompressedOops)

These small language changes (grouped under a project named Coin):

Strings in switch

Automatic resource management in try-statement

Improved type inference for generic instance creation, aka the diamond operator <>

Simplified varargs method declaration

Binary integer literals

Allowing underscores in numeric literals

Catching multiple exception types and rethrowing exceptions with improved type checking

Concurrency utilities under JSR 166

New file I/O library to enhance platform independence and add support for metadata and symbolic links. The new packages are java.nio.file and java.nio.file.attribute

Timsort is used to sort collections and arrays of objects instead of merge sort

Library-level support for elliptic curve cryptography algorithms

An XRender pipeline for Java 2D, which improves handling of features specific to modern GPUs

New platform APIs for the graphics features originally implemented in version 6u10 as unsupported APIs

Enhanced library-level support for new network protocols, including SCTP and Sockets Direct Protocol

Upstream updates to XML and Unicode
Lambda (Java's implementation of lambda functions), Jigsaw (Java's implementation of modules), and part of Coin were dropped from Java 7, and released as part of Java 8 (except for Jigsaw, which will be in Java 9).


From April 2012, Java 7 has been the default version to download on java.com.





Monday, 5 January 2015

Thursday, 25 December 2014

Important Core Java Quetions

  • Can we overload main method?     Java tutorial

You can overload the main() method, but only public static void main(String[] args) will be used   when your class is launched by the JVM. For example:

public class Test {
    public static void main(String[] args) {
        System.out.println("main(String[] args)");
    }

    public static void main(String arg1) {
        System.out.println("main(String arg1)");
    }

    public static void main(String arg1, String arg2) {
        System.out.println("main(String arg1, String arg2)");
    }
}

That will always print main(String[] args) when you run java Test ... from the command line, even if you specify one or two command-line arguments.
You can call the main() method yourself from code, of course - at which point the normal overloading rules will be applied.

Note that you can use a var args signature, as that's equivalent from a JVM standpoint:
public static void main(String... args)


  

  • Constructor returns a value but, what?

First of all ,what actually happens with the constructor is that the runtime uses constructor method to determine how much space is needed to store an object instance in memory. After this space is allocated, the constructor is automatically called as an internal part of the instantiation and initialization process ( if you don't provide values for attributes it will use default values for each type). When the constructor exits, the runtime returns the newly-created instance.
You don't need to write a constructor, because compiler will use one of the built ones, but complex classes will not initialize object correctly, so it's necessary that wee write few of them :).
By a definition in Java constructor don't have return statement. It's by default a instance that is constructed at the moment. Basically you can write something like
public Hello(int a){
aa=a;
return this;
}
In your case, when you are getting errors, it's because Java is strongly typed language, so each function has it's returning type, and constructor always returns an instance of the class. So when you try to return anything that's not a Hello type you will get an error.

  • Can we create a program without main method?

Many Java programmer gives you answer that they can run Java program without main method by writing code in static initializer block, which is half true. Yes, code written in static initializer block is executed before calling main method, but you won't be able to run a class by using Java command, or Eclipse or anything else, until it got  public static void main(String args[]) method on it. If you try to run such programs, you will get following error :


Error: Main method not found in class JavaAppWithoutMain, please define the main
 method
 as:   public static void main(String[] args)





Though you can run a Java program with empty Main method, in which case only code executed will be from static initializer block. Following is a simple Java program with some code written on static initializer block, including a print statement, a variable initialization and starting a thread. As soon as you remove the main method, it will compile fine but will throw above error, when you try to run this program from command line.



public class JavaAppWithoutMain {

    static {
        System.out.println("HelloWorld, Java progarm without main method");
        int x = 20; // Can initialize static variables
        System.out.println("Variable x : " + x);

        Thread t = new Thread() {
            @Override
            public void run() {
                System.out.println("Started thread from static initializer block");
    System.out.println("Thread Finished");
            }
        };
        t.start();
    }

    public static void main(String args[]) {
          // Empty main method
    }

}

Here is how the output look like, when you run this program from command prompt with empty main method.



That's all about whether you can run a Java program without main method in Java or not. In short, Yes, you can run a Java program without main method in a managed environment e.g. Applet,Servlet, and MIDlet, which runs under control of browser, server and mobile device, but can't run a core Java program without public static void main(string args[]) method. JVM will not allow you to execute those methods.





  • What are the 6 ways to use this keyword?

Here is given the 6 usage of java this keyword.
  1. this keyword can be used to refer current class instance variable.
  2. this() can be used to invoke current class constructor.
  3. this keyword can be used to invoke current class method (implicitly)
  4. this can be passed as an argument in the method call.
  5. this can be passed as argument in the constructor call.
  6. this keyword can also be used to return the current class instance.

  • Why multiple inheritance is not supported in java?

In order to enforce simplicity should be the main reason for omitting multiple inheritance. For instance, we can consider diamond problem of multiple inheritance.
We have two classes B and C inheriting from A. Assume that B and C are overriding an inherited method and they provide their own implementation. Now D inherits from both B and C doing multiple inheritance. D should inherit that overridden method, which overridden method will be used? Will it be from B or C? Here we have an ambiguity.


  • Why use aggregation?
If a class have an entity reference, it is known as Aggregation. Aggregation represents HAS-A relationship.
Consider a situation, Employee object contains many informations such as id, name, emailId etc. It contains one more object named address, which contains its own informations such as city, state, country, zipcode etc. as given below.
1.   class Employee{  
2.   int id;  
3.   String name;  
4.   Address address;//Address is a class  
5.   ...  
6.   }  
In such case, Employee has an entity reference address, so relationship is Employee HAS-A address.
Why use Aggregation?
  • For Code Reusability.
When use Aggregation?
  • Code reuse is also best achieved by aggregation when there is no is-a relationship.
  • Inheritance should be used only if the relationship is-a is maintained throughout the lifetime of the objects involved; otherwise, aggregation is the best choice.



  • Can we override the static method?

The answer is ‘Yes’. We can have two ore more static methods with same name, but differences in input parameters. For example, consider the following Java program.
// filename Test.java
public class Test {
    public static void foo() {
        System.out.println("Test.foo() called ");
    }
    public static void foo(int a) {
        System.out.println("Test.foo(int) called ");
    }
    public static void main(String args[])
    {
        Test.foo();
        Test.foo(10);
    }
}
Output:
Test.foo() called
Test.foo(int) called






  • What is covariant return type?

The covariant return type specifies that the return type may vary in the same direction as the subclass.
Before Java5, it was not possible to override any method by changing the return type. But now, since Java5, it is possible to override method by changing the return type if subclass overrides any method whose return type is Non-Primitive but it 


1.   class A{  
2.   A get(){return this;}  
3.   }  
4.     
5.   class B1 extends A{  
6.   B1 get(){return this;}  
7.   void message(){System.out.println("welcome to covariant return type");}  
8.     
9.   public static void main(String args[]){  
10.                new B1().get().message();  
11.                }  
12.                }  

Output: welcome to covariant return type
As you can see in the above example, the return type of the get() method of A class is A but the return type of the get() method of B class is B. Both methods have different return type but it is method overriding. This is known as covariant return type.

  • What are the three usage of super keyword?

  1. super is used to refer immediate parent class instance variable.
  2. super() is used to invoke immediate parent class constructor.
  3. super is used to invoke immediate parent class method.

  • Why use instance initializer block?

Instance Initializer block is used to initialize the instance data member. It run each time when object of the class is created.
The initialization of the instance variable can be directly but there can be performed extra operations while initializing the instance variable in the instance initializer block.