Saturday, 31 May 2014

Introduction to Core Java



JAVA

History of Java
Let's see some points that describe the history of java.
Ø James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991.
Ø Originally designed for small, embedded systems in electronic appliances like set-top boxes.
Ø Initially called Oak and was developed as a part of the Green project.
Ø In 1995, Oak was renamed as "Java". Java is just a name not an acronym.
Ø Originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995.

Java Version History
There are many java versions that have been released.
Ø JDK Alpha and Beta (1995)
Ø JDK 1.0 (23rd Jan, 1996)
Ø JDK 1.1 (19th Feb, 1997)
Ø J2SE 1.2 (8th Dec, 1998)
Ø J2SE 1.3 (8th May, 2000)
Ø J2SE 1.4 (6th Feb, 2002)
Ø J2SE 5.0 (30th Sep, 2004)
Ø Java SE 6.0 (11th Dec, 2006)
Ø Java SE 7.0 (28th July, 2011)

Where it is used?
According to Sun, 3 billion devices run java. There are many devices where java is currently used.

Some of them are as follows:
1.  Desktop Applications such as acrobat reader, media player, antivirus etc…
2.  Web Applications such as irctc.co.in, javapoint.com etc…
3.  Enterprise Applications such as banking applications.
4.  Mobile
5.  Embedded System
6.  Smart Card
7.  Robotics
8.  Games etc...

Types of Java Applications
There are mainly 4 types of applications that can be created using java:

1) Standalone Application
It is also known as desktop application or window-based application. An application that we need to install on every machine such as media player, antivirus etc… AWT and Swing are used in java for creating standalone applications.

2) Web Application
An application that runs on the server side and creates dynamic page, is called web application. Currently, servlet, jsp, struts, jsf etc… technologies are used for creating web applications in java.

3) Enterprise Application
An application that is distributed in nature, such as banking applications etc… It has the advantage of high level security, load balancing and clustering. In java, EJB is used for creating enterprise applications.

4) Mobile Application
 These Applications are created for mobile devices. Currently Android and Java ME are used for creating mobile applications.

Java can be divided into 3 modules.
They are:
Ø JSE (Java Standard Edition)
Ø JEE (Java Enterprise Edition)
Ø JME (Java Micro/Mobile Edition)

JSE
Ø Java is a high level programming language.
Ø Java is a pure OOP language.
Ø Java can be used to develop all kind of software applications so it is called as programming suite.
Ø It is installable software as JDK software.
Ø Latest version is 7.0 or 1.7 (Dolphin)
Ø This module is given to develop stand-alone applications, desktop applications, and two-tier applications…
Ø The application that is specific to one computer and contains main() method is called as stand-alone application.
Ø The stand-alone application that contains GUIness is called as Desktop application.
Ø The application that contains two layers communicating with each other is called as two-tier application.
Note: layer represents logical partition in the application having logics.




There is given many features of java. They are also called java buzzwords.

Simple
Java is simple in the sense that:
Syntax is based on C & C++ (so easier for programmers to learn it after C, C++).
Removed many confusing and/or rarely-used features e.g., explicit pointers, operator overloading etc.
No need to remove unreferenced objects because there is Automatic Garbage Collection in java.

Object-oriented
Object-oriented means we organize our software as a combination of different types of objects that incorporates both data and behavior.
Object-oriented programming (OOPs) is a methodology that simplifies software development and maintenance by providing some rules.
Basic concepts of OOPs are:
        Object
        Class
        Inheritance
        Polymorphism
        Abstraction
        Encapsulation

Distributed
We can create distributed applications in java. RMI and EJB are used for creating distributed applications. We may access files by calling the methods from any machine on the internet.

Robust
Robust simply means strong. Java uses strong memory management. There is lack of pointers that avoids security problem. There is automatic garbage collection in java. There is exception handling and type checking mechanism in java. All these points make java robust.

Secured
Java is secured because:
        No explicit pointer
        Programs run inside virtual machine sandbox.
With Java's secure feature it enables to develop virus-free, tamper-free systems.
Authentication techniques are based on public-key encryption.
Some security can also be provided by application developer through SSL, JAAS, cryptography etc.




Platform Independent
A platform is the hardware or software environment in which a program runs.
There are two types of platforms software-based and hardware-based. Java provides software-based platform.
The Java platform differs from most other platforms in the sense that it's a software-based platform that runs on top of other hardware-based platforms.
It has two components:
        Runtime Environment
        API (Application Programming Interface)

Architecture-neutral
Java compiler generates an architecture-neutral object file format which makes the compiled code to be executable on many processors, with the presence Java runtime system.

High-performance
Java is faster than traditional interpretation since byte code is "close" to native code still somewhat slower than a compiled language (like c, c++ ...)

Interpreted
Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light weight process.

Multi-threaded
A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it shares the same memory. Threads are important for multi-media, Web applications etc.


Difference between JDK, JRE and JVM

JVM
JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java byte code can be executed.
JVMs are available for many hardware and software platforms (i.e. JVM is platform dependent).

The JVM performs four main tasks:
Ø Loads code
Ø Verifies code
Ø Executes code
Ø Provides runtime environment
JRE
JRE is an acronym for Java Runtime Environment. It is used to provide runtime environment. It is the implementation of JVM.  It physically exists. It contains set of libraries + other files that JVM uses at runtime.

JDK
JDK is an acronym for Java Development Kit. It physically exists. It contains JRE + development tools.



API (Application Programming Interface)
Ø It is the base for the programmer to develop certain software technology based applications.
Ø Every software technology used built-in API's. Using these API’s the programmers can develop user defined API’s and software applications.
Ø In "c" language API is set of functions which come in the form of header files.
Ø In "c++" language API is set of functions, classes which come in the form of header files.
Ø In "Java" language API is set of classes, interfaces, enums, annotations which come in the form of packages.
The three types of API in java:
ü Built-in api’s
ü User define api’s
ü Third part api’s

Ø Generally the java related api’s came as in the form of jar files (java style zip file).
Ø rt.jar file represents all the built-in (Official core java) api’s of jdk software.
What happens at compile time?
At compile time, java file is compiled by Java Compiler and converts the java code into bytecode.



What happens at runtime?
At runtime, following steps are performed:


 




Can you save a java source file by other name than the class name?
Yes, like the figure given below illustrates:

 
To compile: javac Demo.java
To execute: java Simple

Can you have multiple classes in a java source file?
Yes, like the figure given below illustrates:
 
In java, there are two types of data types:
Ø primitive data types
Ø non- primitive data types (reference)

 




Data Type

Default Value

Default size

boolean

false

1 bit

char

'\u0000'

2 byte

byte

0

1 byte

short

0

2 byte

int

0

4 byte

long

0L

8 byte

float

0.0f

4 byte

Double

0.0d

8 byte


Why char uses 2 byte in java and what is \u0000?
Because java uses Unicode system rather than ASCII code system. \u0000 is the lowest range of Unicode system.

Unicode System
Unicode is a universal international standard character encoding that is capable of representing most of the world's written languages.


Why java uses Unicode System?
Before Unicode, there were many language standards:
ü ASCII for the United States.
ü ISO 8859-1 for Western European Language.
ü KOI-8 for Russian.
ü GB18030 and BIG-5 for Chinese, and so on.

This caused two problems:
1.  A particular code value corresponds to different letters in the various language standards.
2.  The encodings for languages with large character sets have variable length. Some common characters are encoded as single bytes, other require two or more byte.
To solve these problems, a new language standard was developed i.e. Unicode System. In Unicode, character holds 2 byte, so java also uses 2 bytes for character.
Lowest value: \u0000
Highest value: \uFFFF

No comments:

Post a Comment