Welcome

Sunday 15 September 2013

What are object orientation principles?

According to object oriented paradigm, there are four principles namely:
  • Abstraction
  • Encapsulation
  • Polymorphism
  • Inheritance

Abstraction:
Hiding the complex details and presenting only the general necessary details is known as abstraction. For example, when you go to a car dealer to purchase a car, he/she explains you about the features of the car like: mileage, type of engine, color, details about interior and exterior etc. But, the car dealer never explains about how the engine is built, which nuts and bolts are used build the car etc. The later details are not useful for the buyer. Abstraction is like a concept/theory and encapsulation is the practical implementation of abstraction.

In java, abstraction can be implemented using abstract keyword and interfaces.

Encapsulation:
Wrapping or combining code (methods) and data (instance variables) together is known as encapsulation. Encapsulation provides abstraction. A common side effect of encapsulation is information hiding. For example, there is no need for a person to know about the internal working of a car to drive it. A person interacts with the car through its interface like driving wheel, gear, buttons etc.

In java, encapsulation is implemented using the class concept.
In java, data/information hiding is implemented using the access specifiers.

Polymorphism:
Simply can be defined as many forms or single interface multiple implementations. Polymorphism gives the ability for an object to perform multiple behaviors through a single interface. A real world example for polymorphism is the animal chameleon. Based on the environment, a chameleon can change its body color to save itself from the predators.

In java, polymorphism can be implemented using overloading and overriding.

Inheritance:
Defined as deriving properties and behavior from one class (parent) to another (child) class. For example, consider a general class laptop (parent). All the laptops will have common properties like a screen, keyboard, touchpad etc. and behavior like: laptop starts on the push of a power button.

Now, consider a sub class or child class of laptop like a gaming laptop. A gaming laptop (child class) will have all the properties and behavior of a laptop as mentioned above. In addition, the gaming laptop can have its own properties and behavior.

In java, abstraction can be implemented using the keywords extends and implements.

Note:
If in an interview, you are asked the question, what are the three object orientation principles, you can say:
Encapsulation, Polymorphism and Inheritance.

Saturday 14 September 2013

Is java a pure object oriented programming language?

Short answer for is java a pure object oriented programming language? is yes.

Before java version 5 was released, java was not considered as a pure or full object oriented programming language because of the 8 primitive data types (int, char, float etc...). The problem with these primitive data types is, the values of these types are not objects. They are simply plain values. This is the reason why java was not considered a pure object oriented programming language.

But, in version 5, Java introduced the concept of auto boxing which means whenever a programmer uses a value of the primitive data type, it will be automatically converted to an object of its identical wrapper class behind the scenes. Due to this reason, from java version 5, it is called as a pure object oriented programming language.

Wednesday 11 September 2013

What is java bytecode?

In java, after compilation, the java compiler generates an intermediate non-human readable code. This code file is know as bytecode. The extension of bytecode file is .class.

The bytecode generated by the java compiler is platform independent i.e this code can be executed on a machine with any operating system or any hardware. The bytecode is generated in such a way that when it runs on any machine it gives the same output. This bytecode is executed by the JVM

Q: Why Java is called as portable language or platform independent?
A: Due to the bytecode generated by the java compiler.

Q: Is JVM platform independent?
A: No. It is platform dependent.


What is Just-In-Time compiler in Java?

The Just-In-Time (JIT) compiler is introduced after initial version of Java. In the initial version there was an interpreter due to which the performance of java programs was less (executed slowly). So, they replaced the interpreter with the JIT compiler.

JIT compiler uses hotspot technology. When JVM is executing a java program, the JIT compiler compiles only the necessary set of instructions and those instructions are loaded into the memory and are executed. Due to this java programs are executed at greater speed.

What is Java?

Java is a object oriented programming language developed in 1995 by Sun Microsystems later overtaken by Oracle, which supports all the object orientation concepts like encapsulation, abstraction, polymorphism, inheritance, class, object and more. Java is a popular programming language due to its features.

Other popular object oriented programming languages:
  • C++
  • C#
  • Delphi
  • PHP
  • Python
  • Visual Basic

What is Java Development Kit (JDK)?

Java Development Kit (JDK) is a collection of tool which enables developers to create, test and execute java programs. JDK contains development tools (ex: javac, appletviewer etc...) and Java Runtime Environment (JRE)

Q: What is the difference between JDK and JRE?
A: JDK allows developers to create, test and execute programs whereas JRE only allows users to execute programs.


What is Java Runtime Environment (JRE)?

The Java Runtime Environment (JRE) provides an environment (tools) which allows the execution of java programs (bytecode). JRE is a combination of Java Vitrual Machine (JVM) and the class libraries (predefined packages).

Q: What is the minimum requirement for running (executing) Java programs?
A: Java Runtime Environment (JRE).


Tuesday 10 September 2013

What is Java Virtual Machine (JVM)?

The Java Virtual Machine is a program which is used to execute other programs, generally, java bytecode programs. JVM along with the class libraries (java packages) is the minimum requirement for executing java programs on any device (PC, laptop, mobiles etc...).

Some of the features provided by JVM are as follows:
  • Automated exception handling
  • Memory management (garbage collection)
  • Bytecode verification
JVM is not platform independent. JVM for windows is different from JVM for linux. Similarly JVM for linux is different from JVM for MacOSX and so on.

Main components inside JVM are as follows:
  • Bytecode verifier
  • Memory manager
  • Just-In-Time (JIT) compiler
Java Virtual Machine (JVM) developed by Oracle is named Hotspot.