Wednesday, June 29, 2016

Factory Design pattern

This is another most important design pattern and this is the foundation of Spring, Struts and most of frameworks. Specially this is mostly used in JDK also.

The main advantage of using this method is to hide implementation details from the user. Actually this design pattern is developed using Encapsulation concept. It decouples calling from target class.  Look at the following class diagram and example to understand about Factory design pattern.


Look at this example with above diagram.

Animal.java interface

package com.app.designs.factory;

public interface Animal {
    public void eat();
}



Cat.java class

package com.app.designs.factory;

public class Cat implements Animal {

   @Override
   public void eat() {
       System.out.println("Cat eating"); 
   }
}



Dog.java class

package com.app.designs.factory;

public class Dog implements Animal {

   @Override
   public void eat() {
       System.out.println("Dog eating");
   }
}



AnimalFactory.java class

package com.app.designs.factory;

public class AnimalFactory {

   public Animal buildAnimal(String animalType){
  
      if(animalType==null){
          return null;
      }
      if("dog".equalsIgnoreCase(animalType)){
          return new Dog();
      }
      if("cat".equalsIgnoreCase(animalType)){
          return new Cat();
      }
      return null;
   }
}



Application.java class

package com.app.designs.factory;

public class Application {

   public static void main(String[] args) {
      String animalType = "cat";
  
      AnimalFactory factory = new AnimalFactory();
      Animal animal = factory.buildAnimal(animalType);
      animal.eat();
   }
}




In this example I want to create a cat instance. Then you will be able to see it creates a new Cat object. If you want a Dog object, you need to set animalType to dog. Then it will create a new Dog object. According to the user requirement, system will produce the requested abject. 

This is the core concept behind Spring and Struts frameworks. You may know that there is a concept behind Spring framework called "Dependency Injection". To make it loosely coupled, it uses this factory design pattern inside the framework.


Advantages of Factory design pattern

  • Make code loosely coupled 
  • Hide implementation details from outside

Disadvantages of Factory design pattern

  • It looks your code is more abstract
  • Code becomes complex


Thursday, June 23, 2016

Set interface


This is another core interface in java collection hierarchy. Special thing is Set cannot contain duplicates. Set has three main implements.

  1. java.util.TreeSet
  2. java.util.HashSet
  3. java.util.LinekedHashSet

Common characteristics

  • No duplicates
  • Not thread safe

Other characteristics

  • HashSet is the fastest set implementation, TreeSet is slowest one.
  • HashSet doesn't maintain a order. But LinkedHashSet maintain insertion order while TreeSet maintain sorted order because it implements sortedSet interface.
  • Both HashSet and LinkedHashSet allow null values but TreeSet doesn't allow null values.
  • LinkedHashSet was introduced in 1.4 version in Java.

TreeSet vs HashSet vs LinkedHashSet




Look at the following example to understand about Treeset. It shows about sorting of TreeSet. 

import java.util.Set;
import java.util.TreeSet;

public class TreeSetDemo {

   public static void main(String[] args) {
  
       Set<Integer> treeSet = new TreeSet<>();
  
       treeSet.add(30);
       treeSet.add(10);
       treeSet.add(50);
       System.out.println(treeSet);
   } 
}



Look at the following example to get a brief idea about set interface.

import java.util.Set;
import java.util.TreeSet;

public class TreeSetDemo {

   public static void main(String[] args) {
  
       Set<Integer> treeSet = new TreeSet<>();

  
       treeSet.add(30);
       treeSet.add(10);
       treeSet.add(50);
       System.out.println(treeSet);
  
       System.out.println(treeSet.size());
       System.out.println(treeSet.isEmpty());
       System.out.println(treeSet.contains(500));
       System.out.println(treeSet.remove(10));
       System.out.println(treeSet.equals(50));
       treeSet.clear();
       System.out.println(treeSet);
   }
}



Look at the following example to get an idea about the things that you can do with sets. Following example shows to get distinct characters.

import java.util.Set;
import java.util.TreeSet;

public class TreeSetDemo {

   public static void main(String[] args) {
  
       Set set = new TreeSet<>();
  
       String s = "This is a set interface";
       String []arr = s.split("");
  
       for(String i : arr){
           set.add(i);
       }
  
       System.out.println(set);
   }
}




Wednesday, June 22, 2016

List interface



In my first post of collection you may have an idea about, how to choose a collection. In this post I'm gonna talk about List interface.

List interface can be used if you need an ordered collection which can also have duplicates. There are four special classes which implement List interface.
  1. java.util.ArrayList
  2. java.util.LinkedList
  3. java.util.Vector
  4. java.util.Stack

ArrayList

  • Implemented by using a re-sizable array (Dynamic array).
  • It can contain duplicates.
  • ArrayList is not synchronized .
  • Maintain insertion order.
  • Default initial capacity is very small. Once it is filled its size will be incremented by 50%.
  • It allows random access and it is fast. But Inserting and deleting is slow.
  • This uses iterator to traverse.

LinkedList

  • Implemented by using doubly LinkedList
  • Duplicates are allowed.
  • LinkedList is not synchronized.
  • Maintain insertion order.
  • LinkedList allows sequential access and it slow, but inserting and deleting is fast.
  • LinkedList doesn't have initial size.
  • Compare to ArrayList and Vector, LinkedLIst uses more memory.

Vector

  • Vector looks same as ArrayList.
  • Main difference is, Vector is synchronized.
  • Accessibility is slow, because Vector is synchronized.
  • Once it is filled, initial capacity is incremented by 100%.
  • Vector uses Enumeration to traverse.

Stack

  • This is another simple class which is extended to Vector class.
  • Stack is Last In First Out (LIFO) manner collection.
  • Stack is also synchronized just like Vector, then Stack is also slow.
  • Stack has few special methods, push(), pop() and peek().
Look at the following example about simple operations of Stack.

import java.util.Stack;

public class StackDemo {

   public static void main(String[] args) {
  
       Stack<Integer> stack = new Stack<>();
       stack.push(10);
       stack.push(30);
       stack.push(20);
       stack.push(50);
  
       System.out.println(stack);
       stack.pop();
       System.out.println("After pop : " + stack);
       System.out.println("Head of stack : " + stack.peek());
    }
}




Vector and Stack was introduced in 1.0 version while ArrayList, LinkedList and Collection was introduced in 1.2 version of Java. Because of that, Vector and Stack is called "legacy classes".


You may look at the following example to get an idea about List interface. This example is done by using ArrayList and it can be implemented by using LinkedList and also using a Vector.


public class ArrayListDemo {
 
   public static void main(String[] args) {
  
      List<Integer> list = new ArrayList<>();
      List<Integer> list2 = new ArrayList<>();
  
      list.add(10); //add element to the list
      list.add(20);
      list.add(30);
      list.add(30);
      list.add(0, 100); //add element to given index
      System.out.println(list);
  
      list.remove(1); //remove the element from given index
      System.out.println(list.isEmpty()); //check the list is empty or not
      System.out.println(list.size()); //get the size of list
      System.out.println(list.contains(30)); //check given value is there in list
      System.out.println(list.indexOf(30)); //give index of given value
      System.out.println(list.get(2)); //get value of given index
      System.out.println(list.equals(list2)); //compare two lists
      System.out.println(list.lastIndexOf(100)); //return last index of given value
      System.out.println(list.lastIndexOf(70)); //if not return -1
      System.out.println(list);
  
      list.set(0, 200); //set value to given index
      System.out.println(list);
  
      list.clear(); //clear list
      System.out.println(list);
   } 
}


Using Iterator to traverse

  • Iterator can be used to traverse on ArrayList and LinkedList.
  • You can also use loops to traverse.
  • Look at the following example.

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class ListSpecialMethods {

   public static void main(String[] args) {
  
       List<Integer> linkedList = new LinkedList<>();
       linkedList.add(10);
       linkedList.add(20);
       linkedList.add(30);
       linkedList.add(10);
       linkedList.add(60);
       linkedList.add(80);
  
       showData(linkedList);
   }
  
 
   public static <E> void showData(List<E> list){
       Iterator<E> iterator = list.iterator();
  
       while(iterator.hasNext()){
            System.out.print(iterator.next() + " ");
       }
   }
}

ArrayList vs LinkedList vs Vector vs Stack



RandomAccess interface

  • This is very important when talking about ArrayList and Vector classes.
  • These two classes implements RandomAccess interface.
  • RandomAccess interface is a Marker interface like Serializable and Cloneable interfaces. There is no methods present in these marker interfaces.
  • These interfaces identify classes with the capability of they are defined.

Now you know both ArrayList and Vector classes implement RandomAccess interface. So when you searching and accessing any data inside of ArrayList or Vector, it is too fast than others.




Tuesday, June 21, 2016

Collection interface



Collection interface is the core interface of List, Queue and Set. It consist of core operations that can be used to work with above interfaces.

Basic methods of Collection interface



You may look at the following example which is done using List interface.

package com.app.collections;

import java.util.LinkedList;
import java.util.List;

public class CollectionDemo {

   public static void main(String[] args) {
 
      List list1 = new LinkedList<>();
      List list2 = new LinkedList<>();
  
      list1.add("Apple");
      list1.add("Mango");
      list1.add("Banana");
      System.out.println("List 1 : " + list1);
  
      list2.addAll(list1);
      list2.add("Woodapple");
      System.out.println("List 2 : " + list2);
  
      list2.retainAll(list1);
      System.out.println("List 2 : " + list2);
  
      list2.remove("Apple");
      System.out.println("List 2 : " + list2); 
  
      System.out.println("isEmpty()     : " + list2.isEmpty());
      System.out.println("size()        : " + list2.size());
      System.out.println("hashCode()    : " + list2.hashCode());
      System.out.println("equals()      : " + list2.equals("Apple"));
      System.out.println("contains()    : " + list2.contains("Apple"));
      System.out.println("containsAll() : " + list1.containsAll(list2));
  
      list1.clear();
      System.out.println("clear() : " + list1);
 
   }

}




I think now you have a basic idea of using Collection interface.

Traverse on a collection

There are three main ways to traverse on a collection.
  1. Using loops
  2. Using iterators
  3. Using streams
Third concept is a new one which is introduced after Java 8. At the moment I skip it and looking through first and second ways. Look at the following example.

package com.app.collections;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class CollectionTraverse {

    public static void main(String[] args) {
  
        List list = new LinkedList<>();
  
        list.add("Apple");
        list.add("Mango");
        list.add("Banana");
        list.add("Woodapple");
  
        //Just print the list
        System.out.println(list);
  
  
        //Using a while loop
        int i = 0;
        while(i < list.size()){
            System.out.print(list.get(i) + " ");
            i++;
        }
        System.out.println();
  
  
        //Using a for loop
        for (int j=0; j < list.size(); j++) {
            System.out.print(list.get(j) + " ");
        }
        System.out.println();
  
  
        //print using foreach loop
        for(String s : list){
             System.out.print(s + " ");
        }
        System.out.println();

  
        //print using iterator
        Iterator iterator = list.iterator();
  
        while(iterator.hasNext()){
            System.out.print(iterator.next() + " ");
        }
        System.out.println();

  
        //print using Java 8 foreach loop
        list.forEach(name -> System.out.print(name + " "));
        System.out.println();

    }
}



Serializable interface

This is another important thing when you think about Collection interface. I think you may heard about serialization. Serialization is the process of convert the object into byte stream. Why we need to do this ?

  • To stream through a communication link (One JVM to another)
  • Save data in persistence storage
This is very important for collection framework. Each and every collection class implements Serializable interface by default.

Cloneable interface

This is another important interface which each and every Collection classes are implemented. Cloneable interface is used to get a exact clone of objects for future needs. 

Just think once you got a list of objects, you want to manage it. While you are doing this, sometimes objects may be lost. At the time you'll have to get that list of objects again from the source. But you don't need to worry about this, because every Collection class is implemented Cloneable interface and it can be easily get the same set of objects again.




Queue interface



Queue is another interface which implements Collection interface. This follows First In First Out (FIFO) manner in implementation. This interface has some special methods that can be used to work with it.

Implementing a queue

A queue can be implemented as follows.
  1. Using a LinkedList (java.util.LinkedList)
  2. Using a ProrityQueue (java.util.ProrityQueue)
  3. Using Java concurrency utilities (java.util.concurrent)

Special thing is, a queue which is implemented using Java concurrent package are bounded, others are unbounded. LinkedList is a better approach to implement a queue. Look at the following code to have an idea about queue.

    Queue priorityQueue = new PriorityQueue();
    Queue linkedListQueue = new LinkedList();


If you use a LinkedList to implement a queue, then specially you can add null values also. But it your are using a PriorityQueue, you cannot add null values.

There are some special methods that can be used with a queue. Look at the following methods and at the bottom you can see an example using these methods.

add() vs offer()

  • Both methods can be used to add elements to the queue.
  • But in PriorityQueue, you cannot add null values. It will throw NulPointerException. 
  • But you can add null values in LinkedList implementation of queue. 
  • Main difference can be seen when it happens any error while adding(Capacity exceeding).
  • At the time add() method throws IllegalStateException but offer() method returns false

    Queue<Integer> priorityQueue = new PriorityQueue<>();
    Queue<Integer> linkedListQueue = new LinkedList<>();
  
//  priorityQueue.add(null);
//  priorityQueue.offer(null);
    priorityQueue.add(10);
    priorityQueue.add(20);
    priorityQueue.offer(100);
    priorityQueue.offer(200);  
    System.out.println(priorityQueue);
  
    linkedListQueue.add(22);
    linkedListQueue.add(77);
    linkedListQueue.offer(33);
    linkedListQueue.add(null);
    linkedListQueue.offer(null);
    System.out.println(linkedListQueue);


remove() vs poll()

  • Both methods are used to return the head and remove it.
  • If queue is empty, remove() method throws NoSuchElementException but poll() method returns null.

    priorityQueue.remove();
    linkedListQueue.remove();
  
    priorityQueue.poll();
    linkedListQueue.poll();


element() vs peek()

  • Both methods are used to return the head of the queue.
  • If queue is empty element() methods throws NoSuchElementException but peek() method returns null.

    priorityQueue.element();
    linkedListQueue.element();
  
    priorityQueue.peek();
    linkedListQueue.peek();



Look at the following code which is implemented using a PriorityQueue for a complete reference.

import java.util.PriorityQueue;
import java.util.Queue;

   public class QueueDemo {

       public static void main(String[] args) {
  
           Queue<Integer> priorityQueue = new PriorityQueue<>();
  
           priorityQueue.add(10);
           priorityQueue.add(20);
           priorityQueue.offer(100);
           priorityQueue.offer(200);  
           System.out.println(priorityQueue);

           System.out.println("Remove head using remove()  :" + priorityQueue.remove());
           System.out.println(priorityQueue);
           System.out.println("Remove head using poll()    : " + priorityQueue.poll());
           System.out.println(priorityQueue); 

           System.out.println("Return head using element() : " + priorityQueue.element());
           System.out.println("Return head using peek()    : " + priorityQueue.peek());
  
           priorityQueue.removeAll(priorityQueue);
           System.out.println(priorityQueue);
  
           System.out.println(priorityQueue.poll());
           System.out.println(priorityQueue.peek());
//         System.out.println(priorityQueue.remove());
//         System.out.println(priorityQueue.element());
  
     }
}




The basics of Collection in Java



Collection, this may be another most advanced section in Java. I think you may heard that there are so many things to learn about Collections. Lets begin our journey.


What is the Collection & Collection framework ?

  • Collection is a just a collection of objects or data.
  • Java collection framework is a architecture which is used to manage collections in Java.
  • Java Collection framework is consist of interfaces, implementations and also algorithms.

Core collection interface hierarchy


As you can see, Map is a separate collection interface. Because it stores values with a key.

Advanced collection hierarchy


Click on image for clear view


Click on image for clear view

How to select which Collection is needed ?

Collection hierarchy is a big one, but you can identify it easily. Look at the following diagram. Begin with the blue color checking statement.


Click on image for clear view


Collection vs Collections

  • Collection is a interface and it is the root interface of Java Collection framework.
  • Coillections is a utility class which is from java.util package.
  • Collections class consist of core methods that can be used commonly with List, Set and Queue. 
  • There are so many methods which are defined in Collections class.

List vs Set vs Queue vs Map

Click on image for clear view








Advantages of using Collection framework 

  • No need to learn new APIs or create new APIs.
  • Increase speed and interoperability.
  • Reduce programming effort.
  • It increase software reuse. 




Friday, June 17, 2016

Singleton Design pattern


What is a design pattern ?

  • In simple words, design patterns are best practices in software developing field.
  • These design patters are invented by well experienced Object Oriented Software developers using their practice and experience.

Singleton design pattern

  • This design pattern can be used to control object creation of software development life cycle.
  • If you use Singleton design pattern, then you can have only one instance of that type.

How to create a Singleton object ?

  • Create private constructor (Then no one can instantiate this class, it means others can't create objects)
  • Create the only one private static instance
  • Create a public method to invoke this instance

Types of singleton implementations

There are several ways to implement a singleton class.
  1. Eager initialization
  2. Static block initialization
  3. Lazy initialization
  4. Thread safe initialization
  5. Enum initialization

Eager initialization

  • In this method, the instance is created at the time of class loading.
  • Instance is created even client is requesting or not.

public class Singleton{

    private static final Singleton instance = new Singleton();

    private Singleton() { }

    public static Singleton getInstance() {
       return instance;
    }
}


Static block initialization

  • This is very same as Eager initialization.
  • Special thing is, we use static block in getInstance() method to have exception handling.

public class Singleton{

    private static Singleton instance;

    private Singleton() { }

    static{
        try {
            instance = new Singleton(); 
        }catch (Exception e) {
            System.out.println("Error : " + e);
        }
    }
 
    public static Singleton getInstance(){
        return instance;
    }
}


Lazy initialization

  • This is a good one in single threaded environment.
  • But in multithreaded environment, we have to use thread safe initialization.

public class Singleton{

    private static Singleton instance;

    private Singleton() { }

    public static Singleton getInstance(){
        if(instance == null){
            instance = new Singleton();
        }
        return instance;
    }
}


Thread safe initialization

  • This is just very similar to Lazy initialization.
  • But here synchronize the method that can be used to get the instance in multi threaded environment.

public class Singleton{

    private static Singleton instance;

    private Singleton() { }

    public static synchronized Singleton getInstance(){
        if(instance == null){
             instance = new Singleton();
        }
        return instance;
    }
}

I think you can remember, I have mentioned something called doubled check in thread section. In this method, it is used a synchronized block. Here you can see how to implement this.

public class Singleton {

    private volatile static Singleton instance;

    private Singleton() { }
    
    public static Singleton getInstance() { 
        if (instance == null) {
             synchronized (Singleton.class) {
                  if (instance == null) {
                        instance = new Singleton();
                  }
             }
        }
        return instance;
    }
}


Enum initialization

This is very efficient way to implement a singleton. Because it is very easy to write. Here is the way to implement it.

public enum EnumSingleton{
      instance;
}

You can get the instance by calling EnumSingleton.instance

Which is the best one ?

Enum singleton implementation is the best way, because it is very easy to implement and use. But this is available since Java 5.

When to use Singleton design pattern ?

  • To manage shared resources(Database connections, file manager)
  • Logging
  • Catching

Singleton in JDK

There are many singleton classes that can be found in JDK. I listed three of them.
  • In java.lang.Runtime which provides getRuntime() method.
  • In java.awt.Toolkit which provides getDefaultToolkit() method.
  • In java.awt.Desktop which provides getDesktop() method.

Use of Singleton pattern when creating a database connection


package com.app.design.singleton;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Singleton {

   private static Singleton instance;
   private static Connection connection;
 
   private Singleton(){
  
      String driver = "com.mysql.jdbc.Driver";
      String url = "jdbc:mysql://localhost:3306/database";
      String username = "username";
      String password = "password";
  
      try{
          Class.forName(driver);
              try{
                  connection = DriverManager.getConnection(url, username, password);
              }catch(SQLException e){
                  e.getMessage();
              }
      }catch(ClassNotFoundException e){
          e.getMessage();
      }
   }
 
   public static Singleton getInstance(){
  
      if(instance == null){
          synchronized (Singleton.class){
             if(instance == null){
                 instance = new Singleton();
             }
          }
      }
      return instance;
   }
 
}




Tuesday, June 14, 2016

Nested classes

What does it mean by nested class ?

A class within another class called nested classes. You can define one class within another class as follows.

class Outerclass {
      ...
      class Inner{
          ...
      }
}

What is the purpose of using nested class ?

  • To improve code readability and maintainability.
  • This is the way of grouping classes where all classes are used in one place.
  • To improve code optimization (By increasing encapsulation).
  • This can be used to hide implementation details.

Types of nested classes 



Static nested classes

  • If you create a static class inside of any class is called static nested class.
  • These are called "Top level inner classes".
  • It can access any data of outer class including which are with private access.
  • It can't access to non-static data.

class Outerclass {

    static int i = 10;

    static class StaticInner {
       static void showMessage(){
          System.out.println("Value :" + i);
       }
    }
 
    public static void main(String[] args) {
       Outerclass.StaticInner.showMessage();
    }
}


Non static nested classes (Inner classes)

  • If you create a non static class inside a class but outside of a method is called inner classes.
  • As you can see in above diagram, there are two types of inner classes.


class Outerclass {

   static int i = 10;

   class NonStaticInner {
      void showMessage(){
          System.out.println("Value :" + i);
      }
   }  
 
   public static void main(String[] args) { 
      Outerclass outer = new Outerclass();
      Outerclass.NonStaticInner inner = outer.new NonStaticInner();
      inner.showMessage();
   }
}

Local inner classes

  • A class which is created inside of a method is called local inner classes.
  • You may look at the following example.

public class LocalInnerClassDemo {
 
   void display(){
       int i = 10;
  
       class LocalInner{
           void showMessage(){
                System.out.println("Value : " + i);
           }
       }
       LocalInner inner = new LocalInner();
       inner.showMessage();
   }
 
   public static void main(String[] args) {
       LocalInnerClassDemo classDemo = new LocalInnerClassDemo();
       classDemo.display();
   }
}


Anonymous inner classes

  • This looks same as local inner classes, but anonymous inner classes don't have a class name.
  • Using anonymous classes, you can declare and instantiate a class at the same time.
  • Anonymous classes can be used to concise your code and make it more readable.
  • Anonymous classes can be created using two ways.
    1. Using a class (abstract class or concrete class)
    2. Using an interface

Using a class

abstract class Demo{
     abstract void display();
}

public class AnonymousClassDemo {
 
     public static void main(String[] args) {

         Demo demo = new Demo() {
             void display() {
                 System.out.println("Anonymous Demo");
             }
         };
     demo.display();
     }
}


Using an interface


interface Demo{
    abstract void display();
}

public class AnonymousClassDemo {
 
    public static void main(String[] args) {

        Demo demo = new Demo() {
           public void display() {
               System.out.println("Anonymous Demo");
           }
        }; 
        demo.display();
    }
}



You may need to consider about following things when you create anonymous classes.

  • You have to extend to a class or implement by using a interface.
  • You need to use "new".
  • Anonymous class is just like a expression.
  • You can create local classes and methods in anonymous classes.
  • But you can't create constructors in anonymous classes.

Inner classes in your matters

Inner classes are really useful when creating GUI applications. Think, you just want to make an ActionListener when you click on a button. Once you get it you may think to do it as follows.

myButton.addActionListener(instance);


But unfortunately you forgot that you cannot create objects without implementing to ActionLesterner interface. Then the easiest way to do it, using inner classes.

myButton.addActionListener
(
    new ActionListener()
    {
        public void actionPerformed( ActionEvent e )
        {
            implementation
        }
    }
);









Friday, June 10, 2016

Why Java ?

What are the main features of Java ?


  • Simple
  • Robust & Secure
  • Object Oriented
  • Platform independent
  • High performance
  • Multi-threaded 

Java is Simple

Before Java, "C" is the most powerful language. If you have worked with C, you may feel it is complex than Java and also it is not a Object Oriented programming language. C is Structured oriented language. When Java is invented, is it very easy to understand. Because Java is less complex than C and other languages and it is easy to learn.

Java is Robust and Secure

Java is highly strong programming language. Why I'm saying Java is Robust ? Really Java provide both compile time and run time error checking mechanism. It means there are two error checking gates to ensure your code is correct.

If you have any idea about C language, you may know, C is widely using pointers. But Java doesn't use pointers, it has References. Java is using new keyword to make object. That new returns a reference, not a pointer.

Java is Platform independent 

Platform is a hardware and software combination to run a program. For example Windows, Linux, MacOS. But Java is a software only platform, it means Java can be run in any hardware. 

Java platform is a combination of two components.
  1. JVM (Java Virtual Machine)
  2. Java API (Application Programming Interface)
In my next post I'm gonna talk about JVM architecture. So I skip in this moment. Java API is a set of predefined large collection of ready made software components that can be used when creating Java applications.

Java gives High performance

Java is really built for high performance application creation. Java is running on virtual machine(JVM). You may feel it makes slow execution than native code. But Java's high performance Virtual Machine and compiler gives same performance like native. 

Multi-threading and OOP concepts are described in previous posts. So I skip them for a moment.

Which languages are used in Java ?

  • JVM - Sun JVM is written in C
  • Java compiler - Earlier C and C++, now Java
  • JRE - Written in C
  • Java libraries - Written in Java