Wednesday, 9 October 2013

Why Java

A very interesting and confusing question.....

"WHY JAVA ........?"

The first and foremost reason behind using Java is...
Java is a fun language J 
Why..?

Let’s take a look at some of the reasons:
  •  Java has built-in support for :
    • Multi-threading
    • Socket communication
    • Memory management (automatic garbage collection).
  • Object Oriented Programming language (OOPS).
  • Better portability than other languages across different operating systems.
  • It supports :
    • Web based applications (Applet, Servlet, and JSP)
    • Distributed applications (sockets, RMI, EJB, Web Services etc)
    • Network protocols (HTTP, JRMP etc) with the help of extensive standardized APIs (Application Programming Interfaces).
  • And there are many other multiple reasons that proves that why in today's world everyone wants to switch for Java over other languages.

JRE Structure


JRE Structure
Pictorial Representation of the JRE(Java Runtime Environment)

1.) Class Loader:

Class Loader is a subsystem of JVM that is used to load class files.

2.) Class (Method) Area:

Class(method) Area stores pre-class structures such as runtime constant pool, field and method data , the code for methods.

3.)Heap:

It is the run time data area in which objects are allocated

4.)Stack:

Java Stack stores frames. It holds local variable and partial results, and plays a part in method invocation and return.
Each thread has a private JVM stack, created at the same time as thread.
A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes.

5.)PC(Program Counter) Register:

It contains the address of the java virtual machine instructions currently being executed.

6.)Native Method Stack:

It contains all the native methods used in the application.

7.)Execution Engine:

It contains :
  • A Virtual Processor
  • Interpreter
  • Just-In-Time (JIT) compiler

  

Some Interview Questions

Question 1.-->  What is JVM ?
Answer 1.--> JVM refers to Java Virtual Machine which is a computer program that converts the source code written in java on any operating system to Byte code which a  .class file that can run on any operating system according to the flavour of JVM installed on machine.This constitutes the feature of Platform Independance for Java while JVM is platform dependent.

Question 2.--> What are the concepts of OOPS(Object Oriented Programming) ?
Answer 2.-->  There are basically five concepts of OOPS at ground level but we will see all the 11 concepts of oops.
Those eleven concepts consists of :

  1. Classes and Objects.
  2. Abstraction.
  3. Polymorphism.
  4. Inheritance.
  5. Encapsulation.
  6. Modularity.
  7. Delegation.
  8. Message Passing.
  9. Information Hiding.
  10. Association.
  11. Genericity.

The details of each and every concept described as:

11.) Classes and Objects

A class is simply a representation of a type of object. It is the blueprint/ plan/ template that describe the details of an object. A class is the blueprint from which the individual objects are created. 
Class is composed of three things: a name, attributes, and operations.

An object can be considered a "thing" that can perform a set of related activities. The set of activities that the object performs defines the object's behaviour. For example, the hand can grip something or a Student (object) can give the name or address.

In pure OOPS terms an object is an instance of a class.