You are on page 1of 29

Introduction

to
Juvu Lunguuge
What is 1ava ?
1ava is a technology that makes it easy to
build distributed applications, which are
programs executed by multiple computers
across a network.
1ava is two things :
a programming language
a platform.
%he 1ava Programming Language
1ava is a high level programming language
that is :
Simple
Object-Oriented
Distributed & Dynamic
Portable
Robust
Architecture- Neutral
1ava is Simple
1ava has the bare bones functionality
needed to implement its rich feature
set. It does not add lots of syntactic
sugar or unnecessary features.
1ava is Object Oriented
Almost everything in 1ava is either a
Class, a method or an object. Only the
most basic primitive operations and
data types (int, for, while etc.) are at a
sub-object level.
1ava is Platform Independent
1ava programs are compiled to a byte
code format that can be read and run
by interpreters on many platorms
including Windows N%, Windows 95,
and Solaris 2.3 and later.
1ava is Safe
1ava code can be executed in an
environment that prohibits it from
introducing viruses, deleting or
modifying files, or otherwise
performing data destroying and
computer crashing operations.
igh Performance of 1ava
1ava can be compiled on the fly with a
1ust-in-time (1I%) compiler to code
that rivals C++ in speed.
1ava`s Multi-%hreaded feature
1ava is inherently multi-threaded. A
single 1ava program can have many
different things processing
independently and continuously.
Applet vs. Application
Applet : A 1ava Program that appears to be
embedded in a Web document. %hese
programs are downloaded from the Web by
a web browser and run inside %ML web
pages.
1ava Application
%he 1ava Development Kit (1DK)
%o write 1ava Programs, you need a 1ava
Development Environment.
%he 1ava Developer`s Kit (1DK)
contains the basic tools and libraries
necessary for creating, testing and
executing 1ava Programs.
It also contains a number of useful
utilities for debugging and
documenting 1ava source code.
%he 1ava Development Kit (1DK)
(contd..)
As for the 1DK utilities, there are seven main
programs in the kit:
1. javac : %he java compiler. Converts 1ava source
code into bytecodes.
2. java : %he 1ava interpreter. Executes 1ava
Application bytecodes directly from class files.
3. appletviewer : A 1ava interpreter, that executes
1ava applet classes hosted by %ML files.
.439/
. javadoc : Creates H1ML documentation based
on 1ava source code and the comments therein.
5. jdb : %he 1ava debugger. Allows you to step
through the program one at a time, set
breakpoints and examine variables.
6. javah : Generates C header files that can be used
to make C routines that can call 1ava routines, or
make C routines that can be called by 1ava
programs.
7. javap : %he 1ava disassembler. Displays the
accessible functions and data in a compiled class
file. It also displays the meaning of the bytecodes.
1DK continued.
igure 2.1 on page 37 of Mastering 1ava
A flowchart that outlines the
process by which 1ava Applications
are built using the 1DK
igure 2.2 on page 37 of Mastering 1ava
A flowchart that outlines the process
by which 1ava Applets are built using
the 1DK
%he 1ava Platform
A Platform is the hardware or software
environment in which a program runs.
%he 1ava Platform has two components :
%he 1ava Virtual Machine (1ava VM)
%he 1ava Application Program Interface
(1ava API)
%he 1ava Virtual Machine ( VM)
1ava is unusual in that each 1ava Program is
both compiled and interpreted.
%he 1ava Virtual Machine is a kind of an
idealized 1ava processor chip usually
implemented in software rather than
hardware.
It loads,verifies and executes 1ava bytecodes.
%he 1ava Application Program Interface
1ava`s core API provides a common set of
functions on all platforms.
%he API is a large collection of ready-
made software components that provide
many useful capabilities, such as graphical
user interface (GUI) widgets.
%he 1ava API is grouped into libraries
(packages) of related components.
%he 1ava Application Program Interface
One of these packages includes some core
language functionality such as text
handling and error processing.
%he other packages contain utilities,
networking, I/O, graphical user interface
tools, and interaction with Web browsers.
ow to install the 1DK ?
1DK can be downloaded from the Sun
MicroSystem`s website.
%he 1ava VMs are available for more
than a dozen different hardware-
operating system combinations.
Anatomy of a 1ava Application
The Anatomy oI a Java program is deIined by:
1. Comments in 1ava Code
Comments are remarks added by the
programmer for documentation purposes. %wo
kinds of comments are:
(i) /` ere is a comment that extends across
several lines of text. `/
(ii) // %his comment extends to this line of text.
Anatomy of a 1ava Application(contd..)
2. Defining a Class
%he skeleton of any 1ava Program is a
class definition. In 1ava, each function and
variable exists within a class.
3. %he main Method
%he entry point of every 1ava application
is its main function. %he main method controls
the flow of the program, allocates whatever
resources are needed, and runs any other
methods that provide the functionality for the
application.
Anatomy of a 1ava Application
. Using Classes and Objects
%he other component are the
supporting objects, classes, methods, and the
1ava language statements that are written to
implement the application.
Creating a 1ava Application
Create the source file.
1ava source files are created in a plain text
editor.
On Unix, emacs, pico,vi editors will
work.
On Windows, otepad & DOS Edit text
editors will work.
1ava source files must have the same name as
the class they define and they must have .java
extension.
Example of 1ava Source code
class HelloWorld {
public static void main(String
args[])
{
System.out.println(Hello
World!);
}
}
Note : Save this source code as elloWorld.java
Compiling and Running the source ile
1ava Language is unusual as it is both
compiled and interpreted.
You use the 1ava Compiler (avac) to
compile the program and create .class
files
You use the 1ava interpreter (ava) to
actually run your class files
Compiling the source ile
1o compile the 1ava source file, use the command-
line 1ava compiler that comes with the 1DK.
%o run the compiler, you`ll need to first start
up a DOS shell. In Windows 95, the DOS shell
is MS-DOS prompt.
rom inside DOS, change directories to the
location where you`ve saved the java source
code.
After changing to the right directory, use the
avac command with the name(including .java
extension) of the saved file.
Running the Bytecode
fter the ava source code is successfully
compiled, it gets converted to 1ava bytecode file
with the .class filename extension.
Run the class file using the 1ava bytecode
interpreter.
Use the java command to run it from the
DOS shell. (Note that that the argument to
the java Program does not have a .class
extension)
Summary & Conclusion
1ava is a programming language similar to
C & C++, in which you can develop a
wide range of programs.
1ava`s strength lies in its portability-both
at the source and at the binary level, in its
object oriented design - and in its
simplicity.

You might also like