Lec_4_Introduction to Java
Lec_4_Introduction to Java
Lecture # 4
01/18/25 1
Topics To be Covered Today
• Why Java
• Java History
• Versions of Java
• Features of Java
• Java Procedure
2
What are we doing in this course?
• Learn programming in a high-level programming
language.
• Programming has many paradigms
– Procedural
– Object-Oriented
– Functional
– Logic
• We will study Object-Oriented Programming
using ‘Java’, a popular high-level object-oriented
programming language.
3
Why Java?
• It’s the current “hot” language
• Java mean Cup of coffee
• It’s almost entirely object-oriented
• It has a vast library of predefined objects
and operations
• It’s more platform independent
– this makes it great for Web programming
• It’s more secure
• It isn’t C++
4
Java History
• Java
– was created in 1991
– by James Gosling et al. of Sun Microsystems.
– Initially called Oak, in honor of the tree outside Gosling's
window, its name was changed to Java because there was
already a language called Oak.
5
Java History contd. . . . .
The term Java actual refers to more than just a particular
language like C or Pascal. Java encompasses several parts,
including :
A high level language : the Java language is a high level one that at a
glance looks very similar to C and C++ but offers many unique features
of its own.
Java byte code - a compiler, such as Sun's javac, transforms the Java
language source code to bytecode that runs in the JVM.
Java Virtual Machine (JVM) a program, such as Sun's java, that runs on
a given platform and takes the bytecode programs as input and
interprets them just as if it were a physical processor executing
machine code.
6
Java History contd. . . . .
• Sun provides a set of programming tools such as
javac, java and others in a bundle that it calls a Java
Software Development Kit for each version of the
language and for different platforms such as Windows,
Linux, etc.. Sun also provides a runtime bundle with
just the JVM when the programming tools are not
needed.
7
Versions of Java
Since its introduction, Sun has released a new
version of the Java language every two years or
so.
These new versions brought enhancements, new
capabilities and fixes to bugs.
Until recently, the versions were numbered 1.x,
where x reached up till 4. (Intermediate revisions
were labeled with a third number - 1.x.y - as in
1.4.2.)
The newest version, however, is called Java 5.0
rather than Java 1.5.
8
Versions of Java
• JDK 1.0 (January 23, 1996)
• JDK 1.1 (February 19, 1997)
• J2SE 1.2 (December 8, 1998)
• J2SE 1.3 (May 8, 2000)
• J2SE 1.4 (February 6, 2002)
• J2SE 5.0 (September 30, 2004)
9
Versions of Java
• Java SE 6 (December 11, 2006)
– Java SE 6 Update 10(Released October 15, 2008 )
– Java SE 6 Update 11(Released December 3, 2008)
– Java SE 6 Update 12
– Java SE 6 Update 14(Released May 28, 2009)
– Java SE 6 Update 16(Released August 11, 2009)
– Java SE 6 Update 17(Released November 4, 2009)
– Java SE 6 Update 18(Released January 13, 2010)
– Java SE 6 Update 19(Released March 30, 2010)
– Java SE 6 Update 20(Released April 15, 2010)
– Java SE 6 Update 21(Released July 7, 2010)
10
Versions of Java
• Java SE 7.0
– Java 7 is a major update to Java (July 2011)
11
Features of Java
• Simple & Secure
• object-oriented
• robust – restricts the programmer to find
the mistakes early, performs compile-time
(strong typing) and run-time (exception-
handling) checks, manages memory
automatically.
12
Features of Java
• multithreaded – supports multi-threaded
programming for writing program that perform
concurrent computations
• architecture-neutral – Java Virtual Machine provides
a platform independent environment for the execution
of Java bytecode
• interpreted and high-performance – Java programs
are compiled into an intermediate representation –
bytecode:
– can be later interpreted by any JVM
– can be also translated into the native machine code for
– efficiency.
13
Features of Java
• distributed – Distributed computing allowed
objects on two different computers to execute
procedures remotely.
• dynamic – The linking of data and methods
to where they are located, is done at run-
time.
– New classes can be loaded while a program is
running. Linking is done on the fly.
– Even if libraries are recompiled, there is no need
to recompile code that uses classes in those
libraries.
This differs from C++, which uses static binding.
14
Java Procedure
• The essential steps to creating and
running Java programs go as follows:
– Create a Java source code file
– Compile the source code
– Run the compiled code in a Java Virtual
Machine.
15
Steps for creating and running a Java
program
16
Java Procedure Detail
• You create the code with a text editor (for
example notepad) and save it to a file with
the ".java" suffix.
• All Java source code files must end with this
type name.
• The first part of the name must match the
class name in the source code.
• In the figure the class name is Test so you
must therefore save it to the file name
Test.java.
17
Java Procedure Detail
• With the javac program, you compile this file
as follows:
C:> javac Test.java
• This creates a bytecode file that ends with
the ".class" type appended.
– Here the output is Test.class.
– The bytecode consists of the instructions for the
Java Virtual Machine (JVM or just VM).
18
Java Procedure Detail
The JVM is an interpreter program that
emulates a processor that executes the
bytecode instructions just as if it were a
hardware processor executing native machine
code instructions.
◦ The Java bytecode can then run on any platform in
which the JVM is available and the program should
perform the same.
◦ This Write Once, Run Anywhere approach is a key
goal of the Java language.
19
Another Example with Bytecode
Representation
Test.java
Compile it with
> javac Test.java
Bytecode
Representation
20
Programming Tools
• You can choose from essentially two different programming environments for
Java:
– Manual – with text editor (notepad) create the Java source code files
(*.java) and then use the command line tools in the Java Software
Development Kit (SDK). The SDK is provided by Sun for several platforms
and includes a number of tools, the most important of which are:
• javac - compiles Java source code files (e.g. Test.java) to bytecode
files (e.g. Test.class) *
• java - runs Java application programs (i.e. implements the JVM for the
Java programs.)
• appletviewer - tests applets independently of a browser.
–
21
Programming Tools
– Integrated Development Environment (IDE) - graphical user interface
programming environments (often called GUI Builders) are elaborate,
programs that allow you to interactively build graphical interfaces, edit the
code, execute and run the applets and applications all within the IDE
system. Example Java IDEs include:
• NetBeans
• Borland JBuilder
• Eclipse
• Dr Java
22
Programming Tools
23
Questions?