Java Constructor

Java Constructor :

  • Constructor is used to construct an Object and initialize values
  • By default if no constructor is specified in the code then JVM supplies the constructor at run time.
  • The constructor is supplied by JVM is called default constructor.
  • If the developer doesn’t write the constructor explicitly then the JVM provides default constructor.
  • If your constructor is PRIVATE then the Object is created with in that class.
  • All four Access level modifiers are allowed, but non-access modifiers are not allowed.
  • The class name should be the constructor name.
  • this()constructor or super()constructor must be in the first line.
  • This() and super() cannot come together.
  • Super()constructor calls the super class constructor.
    • Example : super() ? calls the super class constructor with no arguments.
    • Super(1001,’mutn’) ? calls the super class constructor with two arguments.
  • This()constructor calls the constructor with in the same class.
    • Example: this() ? calls the empty constructor.
    • This(1001,’mutn’) ? calls the constructor  with two arguments in the same class.
  • Generally the execution of constructor occurs subclass constructor calls super class constructor, which calls it super class and so on.
  • Finally Object constructor executes and return to the calling constructor, which completes and return to its calling constructor and so on.
  • Constructor cannot be inherited.
  • Default constructor is stopped by JVM when you explicitly specify the constructor.
  • JVM explicitly adds super() keyword as the first line, if this() or super() keyword is not given explicitly.
  • Abstract class can also have constructor.

When I go for static method

When I go for static method :

  • To write utility functions
  • A common code is accessed by different type of object
  • To auto generate a value
    • Example : Id’s
  • To count the number of objects
  • To perform operations on state of all objects belongs to same type .
    • Example: swimming, the total salary of all the employees, finding the highest salary among employees.

History of Java Programming Language

History of Java Programming Language:

Java was developed by James Gosling & his team at Sun Micro systems of USA in the mid of 1991.It was originally called as “Oak”. They started a project called “Green” to demonstrate the application of their new language in 1992.The team developed a Web browser called “Hot Java” to locate and run applet programs on Internet in 1994.In 1995, Oak was renamed as “Java” due to some legal snags.

Flavors of Java:

  • J2SE – Java Platform, Standard Edition
  • J2EE – Java Platform, Enterprise Edition
  • J2ME – Java Platform, Micro Edition

J2SE – Java Platform, Standard Edition:

Java Platform, Standard Edition or Java SE is a widely used platform for development and deployment of portable and versatile applications that are intended for desktop and server environments.

J2EE – Java Platform, Enterprise Edition:

Java Platform, Enterprise Edition or Java EE is Oracle’s enterprise Java computing platform. The platform provides an API and run time environment for developing and running enterprise software, including network and web services, and other large-scale, multi-tiered, scalable, reliable, and secure network applications.

J2ME – Java Platform, Micro Edition:

Java Platform, Micro Edition, or Java ME, is a Java platform designed for embedded systems (mobile devices are one kind of such systems).

Features of Java:

  • Platform Independent
  • Data Security
  • Robustness
  • Multitasking
  • Object oriented
  • Remote Method Invocation
  • Distributed
  • High Performance