Java Programing
Language
SESSION 01 – Introduction to Java
OBJECTIVES
•
•
•
•
•
•
•
•
History of Java
Java Virtual Machine
Features of Java
JRE and JDK
Choosing a development environment
Writing a simple Java program
Using the command-line tools
Using Java NetBeans and Eclipse
History of Java
• Developed and maintained by Sun MicroSystems
(Oracle - 2010)
– Since 1991
– James Gosling
– Originally called Oak
• Aimed at producing an operating environment for
networked devices and embedded systems
– “Write once, run anywhere”
– Java is currently one of the most popular
programming language
The Java history timeline
•
•
•
•
•
•
•
•
•
•
•
1991: Oak Language
1995: Name changed from Oak to Java
1996: JDK 1.0
1997: JDK 1.1
1998: J2EE, J2SE, J2ME
2000: J2SE(EE) 1.3
2002: J2SE(EE) 1.4
2004: J2SE(EE) 5 (1.5)
2006: Java SE(EE) 6
2008: JavaFX 1.0
2011: Java SE 7
J2ME
J2SE
J2EE
6.0
7.0
1.0
1.1
1.4
Java Virtual Machine
• Java is both a compiled and an interpreted language
– Source code is compiled into Java bytecode
– bytecode is then interpreted by the Java Virtual Machine
(JVM)
Java Virtual Machine (cont)
Java Code
Byte Code
(.class)
JVM
Windows
Linux
Mac
Java language for Mobile application development
•
•
•
•
•
•
•
•
•
Android (Java)
Bada (C++)
Black Berry (Java)
iPhone, iPad (Objective-C)
Java Me (Java)
WebOs (C , C++, Javascript, HTML)
Symbian (C++)
Windows Mobile (VC++,C++)
Windows Phone (C#)
Features of Java
•
•
•
•
•
•
•
Simple
Object-Oriented
Platform-independent
Robust
Secure
Distributed
Multi-threaded
Features of Java (cont)
• Simple:
– The syntax is mostly derived from C and C++
– Java has simplified C++ programming by remove
some of complicated and difficult from C++
•
•
•
•
•
•
Goto statement
Overload operator
Pointer
Header
Union, struct
…
Features of Java (cont)
• Object-Oriented:
– Except for primitive data types, everything in Java
is an object
– There are no global functions in Java: all functions
are invoked through an object
– Java’s support for Object-Orientation includes
inheritance, polymorphism, data access levels…
– Not support multiple inheritance
Features of Java (cont)
• Platform-independent:
– Java was conceived with the concept of WORA:
“Write once, Run anywhere"
– Java code (.java) is compiled a byte code which is
independent of the system
– Java byte code (.class) can run on any device
equipped with a Java Virtual Machine
Features of Java (cont)
• Robust: Java can be used to solve some very
complex programming problems with the
supporting of:
– Variety of data types
– Distributed
– Multithreaded
– Garbage collection
–…
Features of Java (cont)
• Secure:
– No pointers are forged.
– No illegal object casts are performed.
– There will be no operand stack overflows or
underflows.
– All parameters passed to functions are of the
proper types.
– Rules regarding private, protected, and public
class membership are followed.
Features of Java (cont)
• Distributed:
– Java facilitates the building of distributed applications by a
collection of classes for use in networked applications.
– By using Java's URL class, an application can easily access a
remote server. Classes also are provided for establishing
socket-level connections.
• Multi-threaded:
– Multiple, synchronized threads is built directly into the
Java language and runtime environment
– Synchronized threads are useful in creating distributed,
network-aware applications
Java compared with other languages
• Java and C/C++
• Java and C#
• Java and script language such as PHP, Perl,
Python, Ruby
• Java and JavaScript
The popularity of Java
JDK and JRE
• The two principal products in the Java SE
platform: Java Development Kit (JDK) and Java
Runtime Environment (JRE).
– The JRE provides the libraries, Java virtual machine,
and other components necessary for running applets
and applications written in the Java programming
language
– The JDK includes the JRE plus development tools such
as compilers and debuggers that are necessary or
useful for developing applets and applications
JDK and JRE
Download and install JDK
• The JDK is a development environment for building
applications, applets, and components using the
Java programming language.
• JDK can be download at
• After downloading the JDK, follow the platformdependent installation directions. At the time of
this writing, they were available at
/>ex.html.
Navigating the Java Directories
• The JDK has the directory structure shown
below:
JDK 1.6.0_<version>
LICENSE
demo
lib
COPYRIGHT
jre
include
README.txt
Readme.html
bin
bin
lib
Setting the Execution Path
1. Click Start > Control Panel > System on
Windows XP or Start > Settings > Control
Panel > System (on Windows XP.)
2. Click Advanced > Environment Variables.
3. Add the location of bin folder of JDK
installation for PATH in User Variables and
System Variables. A typical value for PATH is:
C:\Program Files\Java\jdk1.6.0_<version>\bin
Write a simple Java program
The first application will simply display the greeting "Hello world!"
• Step 1: Create a source file
public class Helloworld
{
public static void main(String[] args)
{
System.out.println("Hello world");
}
}
• Step 2: Compile the source file into a .class file
• Step 3: Run the program
Write a simple Java program
Write Java
code using
an editor
Text Editor
Run the Java
compiler 'javac'
Save the file with a
.java extension
Java code:
Helloworld.java
javac
Helloworld.java
This creates a file of
bytecode with a
.class extension
Bytecode:
Helloworld.class
Execute the
bytecode with the
command 'java'
java Helloworld
Output
Using the Command-Line Tools
• Open a shell indow. Go to directory where you
store your Helloworld.java and use javac
Using the Command-Line Tools
• The javac has a set of standard options:
–
–
–
–
–
–
–
–
–
–
classpath classpath
d directory
encoding encoding
g
help
nowarn
source release
sourcepath sourcepath
target version
…