THOUSANDS OF FREE BLOGGER TEMPLATES

Thursday, April 15, 2010

INTRODUCTION TO JAVA PROGRAMMING

A. A LITTLE BIT OF HISTORY

Java was created in 1991 by James Gosling et al. of Sun Microsystems. Initially calledOak, in honor of the tree outside Gosling's window, its name was changed to Javabecause there was already a language called Oak.The original motivation for Java was the need for platform independent language thatcould be embedded in various consumer electronic products like toasters andrefrigerators. One of the first projects developed using Java was a personal hand-heldremote control named Star 7.At about the same time, the World Wide Web and the Internet were gaining popularity.Gosling et. al. realized that Java could be used for Internet programming.

B. WHAT IS JAVA TECHNOLOGY?

1 . A programming languageAs a programming language,
Java can create all kinds of applications that you couldcreate
using any conventional programming language.

2. A development environmentAs a development
environment, Java technology provides you with a large
suite oftools: a compiler, an interpreter, a documentation
generator, a class file packaging tool,and so on.

3. An application environmentJava technology
applications are typically general-purpose
programs that run on anymachine where
the Java runtime environment (JRE) is installed.

4. A deployment environmentThere are two main
deployment environments: First, the JRE supplied
by the Java 2Software Development Kit (SDK)
contains the complete set of class files for all the
Javatechnology packages, which includes basic
language classes, GUI component classes,and
so on. The other main deployment environment
is on your web browser. Mostcommercial
browsers supply a Java technology interpreter
and runtime environment.

C. SOME FEATURES OF JAVA
1. The Java Virtual MachineThe Java Virtual Machine
is an imaginary machine that is implemented
by emulatingsoftware on a real machine. The
JVM provides the hardware platform specifications
towhich you compile all Java technology code.
This specification enables the Java softwareto
be platform-independent because the compilation
is done for a generic machineknown as the
JVM.A bytecode is a special machine language
that can be understood by the Java
VirtualMachine (JVM). The bytecode is
independent of any particular computer
hardware, soany computer with a Java
interpreter can execute the compiled Java
program, no matterwhat type of computer
the program was compiled on.

2. Garbage CollectionMany programming
languages allows a programmer to allocate
memory during runtime.However, after
using that allocated memory, there should
be a way to deallocate thatmemory block
in order for other programs to use it again.
In C, C++ and otherlanguages the programmer
is responsible for this. This can be difficult
at times sincethere can be instances wherein
the programmers forget to deallocate memory
andtherefor result to what we call memory
leaks.In Java, the programmer is freed
from the burden of having to deallocate that
memorythemselves by having what we call the
garbage collection thread. The garbagecollection
thread is responsible for freeing any memory
that can be freed. This happensautomatically
during the lifetime of the Java program.

3. Code SecurityCode security is attained in Java
through the implementation of its Java RuntimeEnvironment
(JRE). The JRE runs code compiled for a JVM and
performs class loading(through the class loader),
code verification (through the bytecode verifier)
and finallycode execution.The Class Loader is
responsible for loading all classes needed for
the Java program. Itadds security by separating
the namespaces for the classes of the local file
system fromthose that are imported from
network sources. This limits any Trojan horse
applicationssince local classes are always
loaded first. After loading all the classes, the
memorylayout of the executable is
then determined. This adds protection against
unauthorizedaccess to restricted areas of the
code since the memory layout is determined
duringruntime.After loading the class and layouting
of memory, the bytecode verifier then tests
the format of the code fragments and checks
the code fragments for illegal code that canviolate
access rights to objects.After all of these have been
done, the code is then finally executed.

D. PHASES OF A JAVA PROGRAM
The following figure describes the process of compiling
and executing a Java program.· The first step in creating a Java
program is by writing your programs in a text editor.Examples
of text editors you can use are notepad, vi, emacs, etc. This
file is stored in adisk file with the extension .java.·After creating
and saving your Java program, compile the program by using
the JavaCompiler. The output of this process is a file
of Java bytecodes with the file extension.class.·The
class file is then interpreted by the Java interpreter
that converts the bytecodesinto the machine language
of the particular computer you are using.
Task
1. Write the program
2. Compile the program
3. Run the program
Tool to use

1. Any text editor
2. Java Compiler
3. Java Interpreter
Output

1. File with .java extension2. File with .class
extension(Java Byte Codes)3. Program Output

E. DIFFERENCE BETWEEN JAVA APPLICATIONS AND JAVA APPLETS
  • Java applets are java programs that run in a web browser, it is dependent on web browsers.
    -
  • Java applications are stand alone java programs. It can be run in a console window or a graphical user interface.

F. WHAT MAKES JAVA AN OBJECT ORIENTED LANGUAGE

0 comments: