Constructor: – A constructor is a special member function whose main function is to allocate the required resources such as memory and initialize the object of its class. A constructor is distinct from other member function of the class, and it has the same name as its class. It is executed automatically when a class is initialized. It is generally used to initialized object member parameter and allocate the necessary resources to the object members.
The C++ run time system makes sure that the constructor of a class is the first member function to be executed automatically when an object of the class is created. In other word, the constructor is executed every time an object that class is defined. Normally constructor are used for initializing the class data member.
Destructor: – When an object is no longer needed, it can be destroyed. A class can have another special member function called destructor, which is invoked when an object is destroyed. This function compliment the operation performed by any of the constructors, in the sense that, it is invoked when an object ceases to exist. For objects which are local non-static variable, the destructor is called when the function in which object is defined is about to terminate. For static or global variable, the destructor is called before the program terminate. Even when a program is interrupted using an exist() call, the destructor are called for all objects which exist at that time.
The destructor is a member function declared inside the class same as the constructor. But it can be defined either inside or outside of the class. Destructor is a member function having character tilde(~) sign fallowed by the name of its class and a small bracket with or without arguments. It is invoked automatically to reclaim all the resources allocated to the object when the object goes out of scope and is no longer needed.
Package: – The first statement allowed in a java file is a package statement. This statement declares a package name and inform the compiler that the class define here belong to this package. In this section, we can use two different of packages called predefine package and user define package. A predefine package used for various types of application and user define package used for call an application define by the user. The general format of package statement is –
package <Package Name>;
The package statement is optional. That is, our classes do not have to be part of package.
JVM (JAVA Virtual Machine): –
- It is a virtual computer which resides inside JRE.
- JRE is JAVA runtime environment where all runtime supported libraries files one kept.
- When we install JDK (JAVA development kit) to get all necessary tools required for JAVA program development then JRE will also be installed automatically.
- The purpose of JVM is to convent bytecode (.class) file into machine level language (in 0’s & 1’s).
- JVM is platform dependent (i.e. – Windows, Linux, UNIX, Solaris, iOS etc.).
- JVM of one OS Will not be supported on another OS.