Java

What is Java?
Java is a programming language and a platform. Java is a high level, robust, secured and object-oriented programming language.

History of Java?
  • James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991. The small team of sun engineers called Green Team.
  • Originally designed for small, embedded systems in electronic appliances like set-top boxes.
  • Firstly, it was called "Greentalk" by James Gosling and file extension was .gt.
  • After that, it was called Oak and was developed as a part of the Green project.
  • In 1995, Oak was renamed as "Java" because it was already a trademark by Oak Technologies.
  • Java is an island of Indonesia where first coffee was produced (called java coffee).

Features of Java :
  • Simple
  • Object-Oriented
  • Portable
  • Platform independent
  • Secured
  • Robust
  • Architecture neutral
  • Dynamic
  • Interpreted
  • High Performance
  • Multi threaded
  • Distributed

Pro's of Java :
  • Portability (multi-platform).
  • Object-Oriented Programming.
  • Standardization (everything are organized into classes).
  • Lots of pre-made classes.
  • Garbage Collector (take care of unused objects).

Con's of Java :
  • Uses more memory than c++ or c#.
  • Impossibility to use multiple inheritance in classes.
  • Slower (compiled file is a Java byte code).

Setup & Installation :
  • Go to the official website of oracle and download the appropriate jdk version.


  • Accept the license agreement.
   

  • Click on next.

  • Click on close.

  • Go to environment variables and give the path of bin directory where java is being installed.


  • Open command prompt and change the directory where the program is saved. Here i've written a simple java program to print Hello Java.


Basic concepts in java :
Data Structures :
  • In computer science, a data structure is a particular way of organising data in a computer so that it can be used efficiently. 
  • Searching a particular book from millions of books on Amazon or sorting through the endless choice of mobile phones on the basis of price are all done with low cost and low complexity algorithms, which work on structured data.
  • Arrays : This is a data structure that can store a fixed-size sequential collection of elements of the same type. Elements are accessed using indexes.
  • Linked List : This data structure consists of a group of nodes, which together represent a sequence. Under the simplest form, each node is composed of data and a pointer to the next node. This structure allows for efficient insertion or removal of elements from any position in the sequence.
  • Stack : This is a data structure that implements the LIFO (Last In First Out) paradigm. It is like a pile of plates — the one put in last is removed first. It can be implemented both through arrays and Linked List. Push and Pop are the two main operations on the stack. This is basically used in recursion.
  • Queue : This is a FIFO (First In First Out) data structure. It is similar to a queue of people at a movie ticket counter. The first element added to the queue will be the first one to be removed.

String :
    • In java, string is basically an object that represents sequence of char values. An array of characters works same as java string.
    • There are two ways to create a String object.
      • By string literal : Java String literal is created by using double quotes.
      • Example: String s=“Welcome”;  
      • By new keyword : Java String is created by using a keyword “new”.
      • Example: String s=new String(“Welcome”);  It creates two objects (in String pool and in heap) and one reference variable where the variable ‘s’ will refer to the object in the heap.
    • String objects are stored in a special memory area known as string constant pool.
    • Program to add two strings.


    • A part of string is called sub string. In other words, sub string is a subset of another string. In case of sub string start Index is inclusive and end Index is exclusive.


    • To count the number of occurrences of a sub string in a big string.


    OOPS Concepts :

    CLASS : 
    • A Class is a collection of data members and associated methods.
    • When we define a class, memory space is not created for the data members and methods but whose memory space is created when we create an object with respect to a class.
    • Syntax : Class <cls name> { }

    OBJECT : 
    • Instance of a class is called an object.
    • Instance is nothing but allocating the sufficient amount of memory space for the data members and methods of the class.
    • Syntax : <cls name> <obj name> = new <cls name()>;

    DATA ENCAPSULATION :
    • The process of hiding the data or information from external users is called data encapsulation.
    • To implement the data encapsulation we use a keyword private.
    • Private features of a class never participates in profiling process.

    DATA ABSTRACTION :
    • The process of retrieving essential detail with out considering hidden details is called data abstraction.
    • To read data from the keyboard we use one predefined class called scanner.
    • Syntax : Scanner S = new Scanner(System.in);

    INHERITANCE :
    • The process of obtaining the data members and methods from one class to another class is called inheritance.
    • The class which is giving the data members and methods is called super or base or parent class.
    • The class which is taking the data members and methods is called sub or derived or child class.
    • Inheritance is of five types.


    Polymorphism : 
    • The process of representing one form in multiple forms is known as polymorphism.
    • By using method overloading and method over riding we can implement polymorphism.
    • In real world polymorphism is used for developing business logic.