Introduction to Java

Java is a high level programming language.

Features of Java

  1. Object Oriented
    Java is an Object Oriented Programming(OOPs) language. The main concepts of OOPs are
    • Object
    • Class
    • Inheritance
    • Polymorphism
    • Abstraction
    • Encapsulation

  2. PLatform Independent
    Java is a platform independent programming language. Java code can be run on different platforms like Windows, Linux, Mac etc.

  3. Secured
    Java is a secured programming language compared to C programming. One of the main feature of C programming is pointers. Using pointers we can access memory location directly. This is main threat to the security of the application. But in Java there is no pointers. So Java is more secure compared to C. Java program run inside the Virtual Machine(JVM). But C programs run directly in the operating system. So Java is more secure than C.

  4. Architecture Neutral
    In C programming, int data type occupies 2 bytes of memory for 32 bit architecture and 4 bytes for 64 bit architecture. But in Java, it occupies 4 bytes of memory for both 32 and 64 bit architecture. So Java is architecture neutral.

  5. Distributed
    We can create distributed applications in Java. We can access files or data by calling the methods from any machine on the internet. Distributed applications can be created using EJB, Web services etc.

  6. Multithreaded
    We can run multiple tasks simultaneously in Java using Multithreading.

Difference between JVM, JRE and JDK

  1. Java Virtual Machine (JVM)
    Compiler converts the Java code into byte code. JVM loads this byte code and execute this code.

  2. Java Run time Environment (JRE)
    JRE is the implementation of JVM. JRE contains JVM and other libraries for supporting JVM.

  3. Java Development Kit (JDK)
    JDK contains JRE and development tools.
  • JVM, JRE and JDK is platform dependent. But Java is platform independent.
  • For running a Java application JRE is enough. But for developing a Java application JDK is required.

OOPs Concepts

  1. Inheritance
    When one object acquires all the properties and behavior of parent object is known as inheritance. It provides code re-usability.

  2. Polymorphism
    One task is performed by different ways is known as polymorphism. Method Overloading and Method Overriding are two types of polymorphism.

  3. Abstraction
    Hiding internal details and showing functionality is known as abstraction. We use abstract class and interface to achieve abstraction.

  4. Encapsulation
    Binding code and data together into a single unit is known as encapsulation.

Variable

Variable is the name of a reserved memory area. There are three types of variables in Java.
  1. Local Variable
    A variable which is declared inside the method is called local variable.

  2. Instance Varriable
    A variable which is declared inside the class but outside the method is called instance variable. It is not declared as static.

  3. Static Variable
    A variable that is declared as static is called as static variable. It cannot be local.