Introduction to Java
By:
Adnan Amin
Lecturer / Software Programmer
www.geoamins.com
Overview
Short History about Java
Introduction to Java
Bytecode
The Java Environment
By-Adnan Amin (Lecturer/Programmer)
Installing Java
Sample Java Program
Steps for Creating & Running Hello World
Program.
2
Short History about Java
Originally, Sun planned to use C++ for its home
appliance software, but they soon realized that
C++ was less than ideal because it wasn't
portable enough and it relied too heavily on
hard-to-maintain things called pointers.
By-Adnan Amin (Lecturer/Programmer)
Thus, rather than write C++ software and fight
C++'s inherent deficiencies, Sun decided to
develop a whole new programming language to
handle its home appliance software needs.
Their new language was originally named Oak.
The project leader James Gosling's, but it was
soon changed to Java.
Fortunately for Java, the World Wide Web
exploded in popularity and Sun realized it could
capitalize on that. 3
Short History about Java cont..
Web pages have to be very portable because
they can be downloaded onto any type of
computer.
Java programs are very portable and they're
By-Adnan Amin (Lecturer/Programmer)
better than HTML in terms of providing
user interaction capabilities.
Java programs that are embedded in Web
pages are called applets.
Although applets still play a significant role
in Java's current success, some of the
other types of Java programs have applets
in terms of popularity.
4
Introduction to Java
Developed by James Gosling at Sun
microsystem.
By-Adnan Amin (Lecturer/Programmer)
Introduced in 1995.
It is one of the fastest growing programming
technologies of all time.
Multi platform independent.
Case sensitive in syntax.
Used for mobile application, web application,
stand alone and network application etc…
5
Bytecode
Java programs are translated into an
intermediate language called bytecode.
Bytecode is the same no matter which computer
By-Adnan Amin (Lecturer/Programmer)
platform it is run on.
Bytecode is translated into native code that the
computer can execute on a program called the
Java Virtual machine (JVM).
The bytecode can be executed on any computer
that has the JVM.
Hence Java’s slogan, “Write once, run anywhere”.
6
The java Environment
Runs
on
Windows PC
Running JVM
By-Adnan Amin (Lecturer/Programmer)
Cod Compil Re sul
e e t
Java Program Java Compiler Java Bytecode (*.class) UNIX PC
(*.java) javac Running JVM
Macintosh
Running JVM
7
Installing Java
The Java Development Kit (JDK) is a collection of
software available at no charge from Sun
Microsystem, Inc.
The v1.3 , v1.4, v1.5, v1.6 etc download is
By-Adnan Amin (Lecturer/Programmer)
available at http://java.sun.com
In this course, we cover Standard Edition
(SE) Java applications. They are Java
programs that run on a standard
computer – a desktop or a laptop, without
the need of the Internet.
8
Step 1. download jdk 6 for windows
Double click on executable file.
By-Adnan Amin (Lecturer/Programmer)
Then you will welcome installation wizard. Click
Next..
9
Step 2: Custom Setup
Add/Remove the utitlity programs features you
want installed. Then click next…
By-Adnan Amin (Lecturer/Programmer)
10
Step 3: Installing
You will see, the program features you selected
are being installed screen. You must wait for
completion of installation.
By-Adnan Amin (Lecturer/Programmer)
11
Step 4: Finishing & Registration
Finally, you will see the below screen which
indicate that the program has been successfully
installed.
If you want to register the product which is free,
By-Adnan Amin (Lecturer/Programmer)
just click on “Product Registration Information”
button.
Click Finish
12
Sample Java Program
User defined class name of the java program
class Hello
{
By-Adnan Amin (Lecturer/Programmer)
public static void main( String[ ]
args)
{
Body of the program
}
}
running. The main means that this is the main method where the JVM starts runnin
will start
13
Step 1: Try it yourself (Start a notepad)
Click start All Programs Accessories
Notepad
By-Adnan Amin (Lecturer/Programmer)
14
By-Adnan Amin (Lecturer/Programmer)
15
Step 2: Type the code (Notepad)
Step 3: Save the Source code/file
By-Adnan Amin (Lecturer/Programmer)
16
Step 4: run cmd windows
Run CMD command prompt from start menu.
Type and apply the following commands.
By-Adnan Amin (Lecturer/Programmer)
17
Step 5: Execute java program on cmd
Type javac Hello.java (compiler will compile
the source code, the bytecode file
Hello.class will be generated it there are no
By-Adnan Amin (Lecturer/Programmer)
errors).
Type the java Hello (to run the program).
18
Important hints
The file must be named Hello.java to match
the class name containing the main method.
By-Adnan Amin (Lecturer/Programmer)
Java is case sensitive.
This program defines a class called “Hello”.
19
References
Material drawn from [Lewis01, Kjell00,
Mancoridis01]
By-Adnan Amin (Lecturer/Programmer)
20
Installing net beans-6
By-Adnan Amin (Lecturer/Programmer)
for jdk v6.
NEXT Lecture is on….
21
Step 1: open the website & select package
By-Adnan Amin (Lecturer/Programmer)
22
By-Adnan Amin (Lecturer/Programmer)
23
Step 2: Run the Installer
Step 3: Welcome screen Click Next
By-Adnan Amin (Lecturer/Programmer)
24
Step 4: Accept License Agreement Click Next
By-Adnan Amin (Lecturer/Programmer)
25
Step 5: Set the Install files locations
By-Adnan Amin (Lecturer/Programmer)
26
Step 6: Click finish to complete setup
By-Adnan Amin (Lecturer/Programmer)
27