Java Book and Tutorial
Java Book and Tutorial
http://www.ejavatraining.com
Java programming
Introduction to java
Oops Concepts
History of java
Java Architecture
Java Features
Installing Java (JDK1.6 or newer version) on Your System
Writing your First java program
Unit 2
Data Types
Unit 3
Operators
Unit 4
Unit 5
Wrapper Classes
Unit 6
Unit 7
Unit 8
Constructors
Unit 9
Inheritance
Unit 10
Unit 11
Unit 12
Exception Handling
Unit 13
Unit 14
Applets
Unit 15
AWT package
Unit 16
Swings
Unit 18
Unit 19
JDBC
Unit 20
Networking
Unit 21
Unit 22
Util Package
Unit 23
Generics
Unit 24
Introduction to Servlets
Unit 25
Advanced Programming
Introduction to Java
Java is a high-level, third generation programming language, like C, FORTRAN, Smalltalk, Perl, and
many others. You can use Java to write computer applications that play games, store data or do any
of the thousands of other things computer software can do. Compared to other programming
languages, Java is most similar to C++. However although Java shares much of C's syntax, it is not C.
Knowing how to program in C or, better yet, C++, will certainly help you to learn Java more quickly,
but you don't need to know C to learn Java. A Java compiler won't compile C code, and most large C
programs need to be changed substantially before they can become Java programs. What's most
special about Java in relation to other programming languages is that it lets you write special
programs called applets that can be downloaded from the Internet and played safely within a web
browser. Java language is called as an Object-Oriented Programming language and before begining
for Java, we should learn the concept of OOPs(Object-Oriented Programming).
Oops Concepts
There are some basic concepts of object oriented programming as follows:
Object
Class
Data abstraction
Data encapsulation
Inheritance
Polymorphism
Object
An Object is important runtime entity in object oriented programming. This may characterize a
location, a bank account, and a table of data or any entry that the program must handle.
For Example - Employee
Object
Employee
DATA
Id
Name
BasicSalary
GrossSal
Dept
HRA
DA
Methods
InputData()
calGross()
display()
Fig.1.1 Representation of an object Employee
Classes
A class is the collection of objects with similar properties (attributes), common behaviour
(operations), and common link to other objects. The complete set of data and code of an object can
be made a user defined data type with the help of class.
The objects are variable of type class. A class is a collection of objects of similar type. Classes are
user defined data types and work like the build in type of the programming language. Once the
class has been defined, we can make any number of objects belonging to that class. Each object is
related with the data of type class with which they are formed.
As we learned that, the classification of objects into various classes is based on its properties
(States) and behaviour (methods). Classes are used to distinguish are type of object from another.
The important thing about the class is to identify the properties and procedures and applicability to
its instances.
Vehicle
Car
HR-01-9898
Engine - 1200 cc
Fig.1.2 Representation of a Class - Car
In above example, we will create an objects HR-01-9898 belonging to the class car. The objects
develop their distinctiveness from the difference in their attribute value and relationships to other
objects.
Data Abstraction
Data abstraction is also known as data hiding means data abstraction refers to the act of
representing important and required description without including the background details or
explanations.
For Example : Suppose you are driving a car. During the driving a car you can only see steering, accelerator, breaks
, clutch but you dont know how engine is working. You can see only important information in front
of you.
.
Data Encapsulation
Data Encapsulation means wrapping up the data and functions into a single unit (i.e. class). It is
most useful feature of class. The data is not easy to get to the outside world and only those
functions which are enclosed in the class can access it.
Or in other words we can say that binding up the data into a single unit (i.e. Class) is known
encapsulation.
Inheritance
Inheritance is the process by which a sub or derived class inherits the properties of its super or Base
class is known as inheritance.
For Example : -
Grand Father
Father
Polymorphism
(Poly means many and morph means form).Polymorphism mean one thing can be used in many
forms or in other words Polymorphism means the ability to take more than one form.
Polymorphism plays a main role in allocate objects having different internal structures to share the
same external interface. Here I am giving an example to clear the concept of polymorphism.
Suppose I am writing an expression here.
A+B
Here you can see that A+B , but you dont know about the type of A and B. only thing you know that
A and B are going on to add.
But think about + operator , whereas A and B are int ,float ,double or may be an Object but +
operator will add them. Means + operator is one thing and A and B may have many form .Method
overloading, constructor overloading are the examples of Polymorphism.
Dynamic Binding
Dynamic Binding means run time binding. Binding refers to the linking of a procedure call to the
code to be executed in response to the call. Dynamic binding means that the code related with a
given procedure call is not known until the time of the call at run time.
Dynamic binding is associated polymorphism and inheritance.
History of Java:
Java is an object-oriented programming language developed by Sun Microsystems of USA in
1991.Originally called Oak by James Gosling (one of the inventor of the language). Java was
invented for the development of software for cunsumer electronic devices like TVs, tosters, etc. The
main aim had to make java simple, portable and reliable.
Java Authors: James , Arthur Van , and others.
1990
1992
1993
1994
1995
1996
1997
1998
1999
2000
2002
2004
Java Architecture: As we know that all programming language compilers convert the source code into machine code.
Same process done by Java Compiler to run a Java program, but the difference is that Java compiler
OUT PUT
Source code
Complier
Byte Code
Interpreter(JVM)
JAVA Features:
As we know that the Java is an object oriented programming language developed by Sun
Microsystems of USA in 1991. Java is first programming language which is not attached with any
particular hardware or operating system. Program developed in Java can be executed anywhere
and on any system.
Features of Java are as follows:
1. Compiled and Interpreted
2. Platform Independent and portable
3. Object- oriented
4. Robust and secure
5. Distributed
6. Familiar, simple and small
7. Multithreaded and Interactive
8. High performance
1. Compiled and Interpreted
Basically a computer language is either compiled or interpreted. Java comes together both these
approach thus making Java a two-stage system.
Java compiler translates Java code to Bytecode instructions and Java Interpreter generate machine
code that can be directly executed by machine that is running the Java program.
2. Platform Independent and portable
Java supports the feature portability. Java programs can be easily moved from one computer
system to another and anywhere. Changes and upgrades in operating systems, processors and
system resources will not force any alteration in Java programs. This is reason why Java has become