INTRODUCTION
Java was originally called Oak but upon discovering there was another programming language with the same
name, the development team renamed it to Java after one of the brands of coffee. The language grew out of a
project to develop a personal digital assistance [PDA], i.e., a device that was intended to control all electronic
devices used in homes.
Java is a true OO language and therefore the underlying structure of all Java programs is classes. Generally, a
class serves as a template or blueprint for an object and behaves like a basic data type “int”. It is therefore
important to understand how the fields and methods are defined in a class and how they are used to build a Java
program that incorporates the basic OO concepts such as encapsulation, inheritance, and polymorphism.
Characteristics of java
Java attempts to overcome the limitations of its predecessors and as such it is designed to be:
i). Simple: - Java has much in common with C++ but does not have some features that are present in
C++. These features make C++ very powerful but are also very dangerous when in the wrong
hands.
ii). Object oriented: - In java, data and process are encapsulated together to provide objects that have
both state [data] and behavior [process]. This makes it easier for the programmer to model real
world things [objects].
iii). Distributed: - Java is designed for network programming and can easily work with common
internet protocols such as HTTP (hypertext transfer protocol) and FTP (file transfer protocol). It
provides facilities to write systems where programs are distributed across many computers.
iv). Robustness: - A robust program is one that does not behave unpredictably or fail due to
programmer error. Java is more robust compared to other languages because it does not allow
programmers to have direct access to the memory. This is so because pointers are not used in java.
v). Secure: - Java has inbuilt security systems that ensure a code once written is not easy to tamper
with. There are also a number of restrictions placed on what applets can do when they are running
on a remote machine.
vi). Multithreaded: -Java allows many simultaneous activities in one program via the Thread class.
The major benefits are better interactive performance and real-time behavior. For example, images
can be loaded with one thread, while user accesses the HTML information on a Web page.
vii). Architecture neutrality/Platform independent/portability: - Java programs once written can be
run on different operating systems. This is made possible by combining compilation and
interpretation of the source code.
JAVA PLATFORM
It refers to both hardware and software;
Java Virtual Machine (JVM): A layer above the physical hardware of any given machine on which java
code executes. This makes Java platform independent. The JVM is an imaginary machine that interprets the
byte code to run on a specific hardware.
Application Programming Interface (API): A set of inbuilt modules to do common tasks. Java library is
made of packages which in turn are made of classes for common repetitive tasks. Programmers reuse the
packages making programming in java easy.
Object oriented Programming Page 1 of 8
, JDK Editions
Java Standard Edition: - It is used to develop client-side standalone applications or applets.
Java Enterprise Edition: - It is used to develop server-side applications such as Java servlets and Java Server
Pages.
Java Programming Environments
Like other Languages, there are three environments:
Editor – Source code written and edited using text editor. File saved with .java extension
Compiler – Source code translated into byte code and saved in a file with .class extension. The byte code
can be executed on many different kinds of computers. javac program is used to compile.
Execution – java launcher is used to interpret and execute the program.
In command line, the three environments are separate. The following diagram illustrates the Java programming
process
Java IDE Tools
An IDE combines the three environment into one. The following are some common IDEs :
Borland JBuilder
JCreator
Eclipse by IBM
BlueJ
NetBeans by Sun Microsystems, etc.
Java Program Types
Application: - Standalone Java program that can run independent of any Web browser
Applet: - Java program that runs within a Java-enabled Web browser
Servlet: -Java software that is loaded into a Web server to provide additional server functionality similar to
CGI programs
Structure of Java programs
All java programs assume a structure similar to the one shown below.
package packagename;
import java.packagename.*;
[access modifier] class classname [extends superclassname][implements
interfacenamee]
{
//member variable declarations.
type variable name;
//method implementations.
[access modifier] returntype methodname(method parameters)
{
statements in method block;
}// end of method defination
}//end of class definition.
The package keyword is used in the package statement to create or define the package to which a class belongs.
It is optional and when left out, the program is automatically placed in the default package.
Object oriented Programming Page 2 of 8
Java was originally called Oak but upon discovering there was another programming language with the same
name, the development team renamed it to Java after one of the brands of coffee. The language grew out of a
project to develop a personal digital assistance [PDA], i.e., a device that was intended to control all electronic
devices used in homes.
Java is a true OO language and therefore the underlying structure of all Java programs is classes. Generally, a
class serves as a template or blueprint for an object and behaves like a basic data type “int”. It is therefore
important to understand how the fields and methods are defined in a class and how they are used to build a Java
program that incorporates the basic OO concepts such as encapsulation, inheritance, and polymorphism.
Characteristics of java
Java attempts to overcome the limitations of its predecessors and as such it is designed to be:
i). Simple: - Java has much in common with C++ but does not have some features that are present in
C++. These features make C++ very powerful but are also very dangerous when in the wrong
hands.
ii). Object oriented: - In java, data and process are encapsulated together to provide objects that have
both state [data] and behavior [process]. This makes it easier for the programmer to model real
world things [objects].
iii). Distributed: - Java is designed for network programming and can easily work with common
internet protocols such as HTTP (hypertext transfer protocol) and FTP (file transfer protocol). It
provides facilities to write systems where programs are distributed across many computers.
iv). Robustness: - A robust program is one that does not behave unpredictably or fail due to
programmer error. Java is more robust compared to other languages because it does not allow
programmers to have direct access to the memory. This is so because pointers are not used in java.
v). Secure: - Java has inbuilt security systems that ensure a code once written is not easy to tamper
with. There are also a number of restrictions placed on what applets can do when they are running
on a remote machine.
vi). Multithreaded: -Java allows many simultaneous activities in one program via the Thread class.
The major benefits are better interactive performance and real-time behavior. For example, images
can be loaded with one thread, while user accesses the HTML information on a Web page.
vii). Architecture neutrality/Platform independent/portability: - Java programs once written can be
run on different operating systems. This is made possible by combining compilation and
interpretation of the source code.
JAVA PLATFORM
It refers to both hardware and software;
Java Virtual Machine (JVM): A layer above the physical hardware of any given machine on which java
code executes. This makes Java platform independent. The JVM is an imaginary machine that interprets the
byte code to run on a specific hardware.
Application Programming Interface (API): A set of inbuilt modules to do common tasks. Java library is
made of packages which in turn are made of classes for common repetitive tasks. Programmers reuse the
packages making programming in java easy.
Object oriented Programming Page 1 of 8
, JDK Editions
Java Standard Edition: - It is used to develop client-side standalone applications or applets.
Java Enterprise Edition: - It is used to develop server-side applications such as Java servlets and Java Server
Pages.
Java Programming Environments
Like other Languages, there are three environments:
Editor – Source code written and edited using text editor. File saved with .java extension
Compiler – Source code translated into byte code and saved in a file with .class extension. The byte code
can be executed on many different kinds of computers. javac program is used to compile.
Execution – java launcher is used to interpret and execute the program.
In command line, the three environments are separate. The following diagram illustrates the Java programming
process
Java IDE Tools
An IDE combines the three environment into one. The following are some common IDEs :
Borland JBuilder
JCreator
Eclipse by IBM
BlueJ
NetBeans by Sun Microsystems, etc.
Java Program Types
Application: - Standalone Java program that can run independent of any Web browser
Applet: - Java program that runs within a Java-enabled Web browser
Servlet: -Java software that is loaded into a Web server to provide additional server functionality similar to
CGI programs
Structure of Java programs
All java programs assume a structure similar to the one shown below.
package packagename;
import java.packagename.*;
[access modifier] class classname [extends superclassname][implements
interfacenamee]
{
//member variable declarations.
type variable name;
//method implementations.
[access modifier] returntype methodname(method parameters)
{
statements in method block;
}// end of method defination
}//end of class definition.
The package keyword is used in the package statement to create or define the package to which a class belongs.
It is optional and when left out, the program is automatically placed in the default package.
Object oriented Programming Page 2 of 8