INTRODUCTION
Java is a popular third generation programming
language, which can be used to do any of the
thousands of things that a computer software can do.
With the features it offers, java has become the
language of choice for Internet application. Java plays
an important role for the proper functioning of many
software-based devices attached to a network. The kind
o functionality the java offers, has contributed a lot
towards the popularity of java.
ABOUT JAVA
Java is both a programming language and a platform.
Like any other programming language, you can use
java to write or create various types of computer
applications .Thus, Java fits the definition of a
programming language. Java is also a platform for the
application development. The word platform generally
is used to refer to some combination of hardware and
system software e.g., operating system Windows Vista
on the Intel Pentium V or Windows NT on DCE Aiphas or
System 8.5 on the PowerMacs etc.
The Java platform is a new software platform different
from many other platforms ; it is designed to deliver
and run highly interactive, dynamic and secure
application on networked computer systems.
HISTORY OF JAVA
Do you know that Java was not developed keeping in
mind the world wide web ? originally , Java started as
an elite ( code name green ) to find a way of allowing
difference electronic devices such as T.V-top boxes and
controllers to use a common language. This language
for electronic devices was originally named Oak but
failed to find a niche despite its potential
Java programming language was written by James
Gosling along with to other person Mike Sheridan and
Patrick Naughton, while they were working at Sun
Microsystems. Ever since it’s introduction, it has gone
through many changes.
Major Milestones in Java history are : release of source
code of Java virtual machine (JVM) as free and open –
source software,(FOSS), under the terms of the GNU
General Public License (GPL) in the first decades of 21 st
century ; and acquisition of sun Microsystems by oracle
Corporation by the end of same decade.
Java comes in various platforms:
Java card for smartcards.
Java Platforms , Micro Edition (Java ME)- targeting
enviorments with limited resources.
Java Platforms , Enterprise Edition (Java EE)-
targeting large distributed enterprise or Internet
environments.
Java Platform, standard Edition (Java SE)-
targeting workstation environments.
BYTECODE
Do you know that computer programs are very
closely tied to the specific hardware and operating
system they run on. For ex.: a windows program
will not be able to run on a computer that only runs
DOS; A Mac application can’t run on Unix
Workstation and so on.
To tackle with diversity of platforms, major
commercial application like MS-Word or Netscape
Navigator have to be written almost independent
for all different platforms they run on.
But for the applications developed with Java, this is
no case. For, these applications are platform-
independent i.e., they are not affected with
changing platforms. Java solves the problem of
platforms-independence by using byte code. In
order to understand byte code, you must clear
about compilation process first, which is being
discussed below.
ORDINARY COMPILATION PROCESS
As you know that program is a set of instructions
given to a computer. The program or code written
by a programmer is usually called the Source
Code. This source code needs to be converted into
machine language code, which computer can
easily understand. The process of converting a
source code into machine code, is compilation. The
converted machine code depends a lot on the
platform it is executing upon. That means for
different platforms different machine code is
produced. This resultant machine code is
called native executable code.
Java is a javac- a program that complies Java source
code (Java programs ) into compiled byte code.
There is an alternative to compiling a high level
language program. Instead of using a compiler, which
translate the program all at once, you can use an
interpreter, which translates it instruction-by-
instruction, as necessary. In order to execute a
program the interpreter repeatedly reads one
instruction from the program, decides what is
necessary to carry out that instruction, and then
performs the appropriate machine language commands
to do so
JAVA COMPILATION
Contrary to ordinary compilers, the Java compiler does
not produce native executable code for a particular
machine. Instead it produces a special format called
byte code. The Java byte code looks a lot like machine
language, but unlike machine language Java byte code
is exactly the same on every platform. This byte code
means the same thing on a Solaris workstation as it
does on a Macintosh Power Book or on Windows Vista
running on a Intel Pentium V. However, the Java
programs that have been compiled int byte code still
need interpreter to execute them on any given
platform. The interpreter reads the byte code and
translates it into the native language of the host
machine on the fly. Since the byte code is completely
platform independent, only the interpreter and a
libraries need to be ported to get Java to run on a new
computer or operating system.
JAVA VIRTUAL MACHINE (JVM)
As you are aware that any source program needs to be
either compiled or interpreted before it can be
executed. But with Java a combination of these two is
used.
Programs written in Java are compiled into Java byte
code, which is then interpreted by a special Java
Interpreter for a specific platform. Actually this fau
interpreter is known as the Java Virtual Machine (JVM).
The machine language for the virtual Machine is called
Java byte code. Actually the java interpreter running on
any machine appears and behaves like a virtual
processor chip, that is why, the name- Parow Vinter
Machine. The Java Virtual Machine is an abstract
machine designed to be implemented on top of existing
processors. It hides the underlying operating system
from java application The Java Virtual machine can be
implemented in softwew or hardware.
JVM combined with Java API makes Java Platform. The
Java API (Application Programming Interface) are
libraries of compiled code that can be used in your
programs in other words the Jaw API consists of the
functions and variables that programmes are allowed to
use in their applications.
Thus you can write a Java program (java files) on any
platform and use the JVM compile(called javac) to
generate a bytecode file(.class files). This bytecode file
can be used an at platform that has installed Jav.
However, do note that byte code is not an executable
file execute a bytecode file, you can actually need to
invoke a java interpreter(called java). Ever platform has
its own java interpreter which will automatically
address the platform-speatic issues. When platform-
specific operations are required by the bytecode, the
Java interpro fills this need by linking in appropriate
code specific to the platform. The JVM compiler
(java)compiles the Java source code program file (java
files into by code class file), which can then be
executed using Java interpreter program
CHAEACTERISTICS OF JAVA
Although Java has many and many characteristics that
make it eligible for a powerful and popular language. In
the following lines, we are going to discuss a few
important
Characteristics of Java.
Write once Run Anywhere(WORA).The java
programs need to be written just one, which can be
run on different platforms without making changes
in the Java program Only the Java interpreter is
changed depending upon the platform.
Light Weight Code. With java, big and useful
applications can also be created with very light
code. No huge coding is required.
Security java offers many security features to
make its programs safe and secure.
Built-in Graphics. Java offers many built-in graphics
Features and routines which can be used o make
java application more visual.
Object-Oriented Language. Java is object-oriented
language, thereby, very near to real world.
Supports Multimedia. Java is ideally suited for
integration of video, audio, animation and graphics
in internet environment.
Platform independent. Java is essentially platform
independent. Change of platform does not affect
the original Java program/application.
Open product. Java is an open product, freely
available to all. However, there exist some special
time-saving Java development kits, which can be
availed by paying small amounts.
JAVA FUNDAMENTALS
Character set
Java uses the Unicode character set. Unicode
is a two-byte character code set that
characters representing almost all characters
in almost all human alphabets and writing
systems around the world including English,
Arabic Chinese and many more.
Keywords
Keywords are the words that convey a special
meaning to the language compiler. These ate
reserved for special purpose and must not be
used as normal identifier names.
Identifiers
Identifiers are the names given by the
programmer to various program units of java.
Identifiers are the names of variables,
methods, classes, packages and interfaces
etc. Identifiers forming rules of java state the
following :
1. Identifiers can have alphabets, digits,
underscore and $ characters ad can be of
any length
2. They must not be a keyword or Boolean
literal or null literal.
3. They must not begin with a digit.
4. Java is case sensitive i.e., upper-case letters
and lower- case letters are treated
differently.
Literals
Literals ( often referred to as constants) are
data items that are fixed data values. Java
allows several kinds of literals:
1.Integer literals. Integer literal are whole
numbers and can be written in decimal form
(starts with a non zero number eg.10),octal
form (starts with zero,eg.,012)and
hexadecimal form(starts with a Ox,eg., 0xC).
2. Floating-point literals. Floating point
literals are numbers with fractional point or the
numbers having decimal points. These can be
written either in fractional form eg. 0.00036 or in
exponent form,e.g., 0.36E-3.
3.Boolean literals . These literals are
represented by true and false.
4.Character literals. Single character or
escape sequence enclosed in single quotation
marks makes a character literal e.g., ‘a’ and t
are character literal.
5. String literals. One or more characters
enclosed in double quotation marks make a
string literal,e.g., “abc”, “T189” etc,
6. Null literal. The null literal represent null
reference and written as null.
Variables
A variable is a named memory location, which
holds a data value of a particular data type. A
variable is declared as type variable name;
Constants
A constant value represents a named value
that remains fixed throughout the program.A
constant is declared in similar way as a
variable but with keyword final,e.g.,
Final double TAXRATE=0.25;
Operators
The operation being carried out are
represented by operators. Java provides a
wide range of operators.
-Arithmetic Operators
-Increment/Decrement Operators
-Relational Operators
-Logical Operators
-Bitwise Operators
-Assignment,?:and Operators
Expression
An expression in java is any valid combination
of operators, constants, and variables i.e., a
legal combination of java tokens. The
expression in java can be of any type:
arithmetic expression, relational(or logical)
expression, compound expression etc. Type of
operators used in an expression determines
the expression type. For instance, if an
expression is formed using arithmetic
operators, it is an arithmetic expression; if an
expression has relational and Boolean
operators, it is a Boolean expression. When an
expression is evaluated, the data type of its
variable/ operands play an important role. The
data type of an operand may be internally
changed / converted.
Java statements
A statement forms a complete unit of execution.
A group of statements, enclosed curly
brackets{}is called a block and is treated as one
compound statement Control flow statements
like if and switch help you with selection, for,
while and do..while help you with iteration of
statements and break and continue are jump
statements.
Methods
In java, all the functionality exists inside a
class. A class has data members(variables and
constant) and functionality is added via
methods. A method can exist only inside a
class.
Method definations have following two parts:
1.The header and 2. The body
The method header comprises of the access
modifiers (public static), return type(double in
case of method) , method name, and
parameters, i.e., the values sent to the
method(double a, double b in case of above
method).The method body is a block
statementthat immediately follows the method
header.
The method body defines functionality through
java statements in this block. After executing
method body, method returns a value of return
type.
WRAPPER CLASS
Integer class
It is a wrapper class for primitive data type int.it
wraps an int value in an object. Provides method
for converting an int to a string object and a string
object to an int .
Main difference between parseInt() andvalueOf()
methods is that first one returns an int value
whereas later one returns Integer object.
Methods
Description
static int parseInt(String s) convert s String s to an
int using radix10
static Integer valueOf (string s) converts a String s to
an integer object
static string to String(int n) converts an int n to a
String object
String to String() Converts an invoking
object to a String
Byte class
A wrapper class for primitive data type byte. It
wraps a byte value in an object. Provides methods
for converting a byte to a String object and String
object to a byte
Methods
Description
static Byte parseByte(String s) converts a String s to
a byte
static Byte valueOf(String s) converts a String s to
a Byte object
static String to String(byte n) converts a byte n to a
String object
String to String() converts an invoking
object to a String
Short class
Wrapper class for primitive data type short. It
wraps a short value in an object. Provides methods
for converting a short to a String object and a
String object to a short .
Methods Description
static Short parseShort(String s) converts s string s to a
short
static Short valueOf(String s) converts a String s to a
Short object
static String to String(short n ) converts an short n to a
string object
String to String() converts an invoking
object to a String
Long class
Wrapper class for primitive datatype long. Wraps
a long value in an object. Providesmethods for
converting a long to a String object and a String
object to a long
Methods Description
static long pareInt(String s ) converts a String s to a
long
static Long valueOf(String s) converts a String s to an
Long object
static String to String(long n ) converts an long n to a
String object
String to String() converts an invoking
object to a String
Float class
Wrapper class for primitive data type float. Wraps
a float value in an object. Provides methods for
converting a float to a String object and a String
object to a float.
Methods Description
static float parseFloat(String s) converts a String s to a
float
static float valueOf(String s ) converts a String s to a
Float object
static String to String (float n) converts an float n to a
String object
String to String() converts an invoking
object to a string.
Double class
Wrapper class for primitive data type double.
Wraps the double value in an object. Provides
methods for converting a double to a String object
and a String object to a double.
Methods Description
static double parseDouble(String s) converts a String s to
a double
static Double valueOf(String s) converts a String s to
an Double object
staticString to String (double n ) converts an double n
to a String object
String to String() converts an invoking
object to a String
Character class
Wrapper class for the primitive data type chare
and it wraps a char value in an object. Provides a
char value to repre method that returns the char
value contained in an object.
Methods Description
static booleanisDigit (char ch) Returns true if ch is
a numeric digit
between 0 and 9;
otherwise false.
static Boolean is Letter(char ch) returns true if ch is
letter otherwise
returns false
static boolean is LetterOrDigit(char ch) returns true if ch is a
letter or a digit
otherwise returns
false
static boolean isLowerCase(char ch) returns true if ch is a
lowercase
otherwise returns
false
static boolean isUpperCase(char ch) returns true if ch is
a uppercase
otherwise returns
false
static boolean isWhiteespace(char ch) returns true if ch is
a whitespace
otherwise returns a
false
static char to LowerCase(char ch) returns a lowercase
equivalent of
ch
static char to Uppercase(char ch) returns a uppercase
equivalence of
ch