Lec2-Introduction To JAVA
Lec2-Introduction To JAVA
Programming Language
Lecture 2
Based on Slides of Dr. Norazah Yusof
1
Origins of the Java Language
• Java was created by Sun Microsystems team led by Patrick Naughton and
James Gosling (1991)
• Originally named Oak (Gosling liked the look of an oak tree that was right
outside his window at Sun)
• Intended to design a small computer language that could be used for
consumer devices/appliances such as the cable TV switchboxes.
– It is a difficult task because these devices do not have a lot of power or
memory, the language had to be small and generate very tight code.
Also, because different manufacturers may choose different central
processing units (CPUs), it was important that the language not be tied
to any single architecture.
• The team developed a two-step translation process to simplify the task of
compiler writing for each class of appliances
2
Origins of the Java Language
• Significance of Java translation process
– Writing a compiler (translation program) for each type of
appliance processor would have been very costly
– Instead, developed intermediate language that is the same
for all types of processors : Java byte-code
– Therefore, only a small, easy to write program was needed to
translate byte-code into the machine code for each processor
3
Origins of the Java Language
• Patrick Naughton and Jonathan Payne at Sun Microsystems
developed a Web browser that could run programs over the
Internet (1994) and evolved into the HotJava browser.
– Beginning of Java's connection to the Internet
– To show off the power of applets, they made the browser
capable of executing code inside web pages.
• Netscape Incorporated made its Web browser capable of
running Java programs (1995)
– Other companies follow suit
4
The Java Language
• Java is a full-featured, general-purpose programming
language that is capable of developing robust mission-critical
applications.
• Today it is used for developing stand alone applications,
desktops, web programming, servers, and mobile devices.
– Java can be run on the web browser called the applets.
– Java can also be used to develop applications on the server side,
called Java servlets or Javaserver pages (JSP)
– Java can be used to develop applications for small hand-held
devices, such as personal digital assistants and cell phones.
5
The Java Language Specification
• Java language specification defines the Java standard and the
technical definition of the language that includes the syntax
and semantics of the Java programming language.
– stable
• Java application program interface (API) contains predefined
classes and interfaces for developing Java programs.
– Still expanding
6
Java API
• Java 1.0 was introduced in 1995.
• December 1998, Sun announced the Java 2 platform – the
brand that applies to current Java technology.
• There are 3 editions of the Java API:
– Java 2 standard edition (J2SE)
• client-side standalone applications or applets
– Java 2 Enterprise Edition (J2EE)
• server-side applications, such as Java servlets and
JavaServer Pages
– Java 2 Micro Edition (J2ME)
• mobile devices, such as cell phones
7
Java Language
8
Java API
9
J2SE version
• There are many versions of J2SE.
• The latest version is J2SE 6.0.
• Sun releases each version of J2SE with a Java Development
toolkit (JDK)
• For J2SE 5.0, the Java development toolkit is called JDK 5.0 –
formerly was known as JDK1.5
• JDK consists of a set of separate programs for developing and
testing Java programs, each of which is invoked from a
command line.
10
Java Development Tools
• Java development tool is a software that provides an integrated development
environment (IDE) for rapidly developing Java programs.
• Other Java development tools on the market (besides JDK 5.0):
– JBuilder by Borland
– NetBeans Open Source by Sun
– Eclipse Open Source by IBM
• Other useful tools:
– Code warrior by Metrowerks
– TextPad Editor
– JCreator LE
– JEdit
– JGrasp
– BlueJ
– DrJava
11
Java Program
• Java program can be written in many ways:
– Applications
– Applets
– Servlets
12
Java Applications
• A Java applications or "regular" Java programs are standalone
programs that can be executed from any computer with a
JVM.
• It is a class with a method named main
– When a Java application program is run, the run-time system
automatically invokes the method named main
– All Java application programs start with the main method
13
Java Applets
• A Java applet (little Java application) is a Java program that is
meant to be run from a Web browser
– Can be run from a location on the Internet
– Can also be run with an applet viewer program for debugging
– Applets always use a windowing interface
14
Java Servlets
• A Java servlets are special kind of Java programs that run from
a Web server to generate dynamic Web contents.
15
Objects and Methods in Java
• Java is an object-oriented programming (OOP)
language
– Programming methodology that views a program
as consisting of objects that interact with one
another by means of actions (called methods)
– Objects of the same kind are said to have the
same type or be in the same class
16
The Compiler and the Java Virtual Machine
17
The Compiler and the Java Virtual Machine
18
Byte-Code and the Java Virtual Machine
(JVM)
• The compilers for most programming languages translate
high-level programs directly into the machine language for a
particular computer
– Since different computers have different machine languages,
a different compiler is needed for each one
• In contrast, the Java compiler translates Java programs into
byte-code, a machine language for a fictitious computer called
the Java Virtual Machine
– Once compiled to byte-code, a Java program can be used on
any computer, making it very portable
19
The Compiler and the Java Virtual Machine
20
Program Development Process
Saves Java statements
Text editor Source code
(.java)
r ea d by
Is
Produces Byte code
Java compiler (.class)
t e d by
t er pre
Is i n
Java Results in Program
Virtual Execution
Machine
21
Portability
•Windows •Unix
•Macintosh •BSD
•Linux •Etc.
22
Portability
• With most programming languages, portability
is achieved by compiling a program for each
CPU it will run on.
• Java provides an JVM for each platform so
that programmers do not have to recompile for
different platforms.
23
Portability
Byte code
(.class)
Java Virtual
Java Virtual
Machine for Windows
Machine for Unix
24