Object Oriented Programming (CSC241 )
INTRODUCTION TO JAVA
COMSATS University Islamabad, Abbottabad Campus
OUTLINE
Introducing Java
Key features of the language
Java Virtual Machine & Runtime Environment
Installation and Environment Setting
Useful Resources
2
SOME HISTORY
Developed and maintained by Sun Microsystems
In 1990s
Originally called Oak
Aimed at producing an operating environment for
networked devices and embedded systems
…but has been much more successful
Design objectives for the language
Simple, object-oriented,
Distributed, multi-threaded, and platform neutral
Robust, secure, scaleable (ability to grow)
3
KEY FEATURES
JAVA IS SIMPLE
JAVA IS OBJECT-ORIENTED
JAVA IS DISTRIBUTED
JAVA IS compiled and INTERPRETED language at the
same time
JAVA IS ROBUST/adopt changes
JAVA IS ARCHITECTURALLY NEUTRAL
JAVA IS PORTABLE
JAVA IS HIGH-PERFORMANCE
JAVA IS DYNAMIC
4
LANGUAGE FEATURES
Java is both compiled and interpreted
Source code is compiled into Java bytecode
Which is then interpreted by the Java Virtual Machine (JVM)
Therefore bytecode is machine code for the JVM
Java bytecode can run on any JVM, on any platform
…including mobile phones and other hand-held devices
Networking and distribution are core features
In other languages these are additional APIs
Makes Java very good for building networked applications,
server side components, etc.
5
FEATURES OF THE JVM
The Garbage Collector
Java manages memory for you, the developer has no control over
the allocation of memory (unlike in C/C++).
This is much simpler and more robust (no chance of memory leaks or
corruption)
Runs in the background and cleans up memory while application is
running
The Just In Time compiler (JIT)
Also known as “Hot Spot”
Continually optimises running code to improve performance
Can approach the speed of C++ even though its interpreted
6
VERSIONS OF JAVA
Java Language vs Java Platform
Current version of the language is java 7
Core language plus additional APIs is called the Java platform
Three versions of the Java Platform, targeted at different uses
Java Micro Edition (Java ME)
Very small Java environment for smart cards, pages, phones
Subset of the standard Java libraries aimed at limited size and
processing power
Java Standard Edition (Java SE)
The basic platform, for desktop applications
Java Enterprise Edition (Java EE)
For business applications, web services, mission-critical systems
Transaction processing, databases, distribution, replication
7
JAVA VIRTUAL MACHINE & RUNTIME ENVIRONMENT
When you write a program in C++ it is known as
source code. The C++ compiler converts this
source code into the machine code of underlying
system (e.g. Windows) If you want to run that code
on Linux you need to recompile it with a Linux
based compiler.
Due to the difference in compilers, sometimes you
need to modify your code.
Java has introduced the concept of WORA (Write
Once Run Anywhere).
8
JAVA VIRTUAL MACHINE & RUNTIME
ENVIRONMENT
9
THE JAVA APIS
Sun are constantly adding new features and APIs
The Core Java API is now very large
Often difficult to keep up with every change
Separate set of extension APIs for specific purposes
E.g. Telephony, Web applications, Game programming
All new developments reviewed through Java Community
Process ([Link]
Chance for developers to provide feedback on emerging standards
and APIs
Useful to keep an eye on what's coming through
Also a wide range of “open source“ APIs available
E.g. through the Jakarta project ([Link]
10
JAVA VIRTUAL MACHINE (JVM)
The central part of java platform is java virtual
machine
Java bytecode executes by special software known as
a "virtual machine".
Most programming languages compile source code
directly into machine code, suitable for execution
The difference with Java is that it uses bytecode - a
special type of machine code.
The JVM executes Java bytecodes, so Java bytecodes
can be thought of as the machine language of the
JVM. 11
JAVA VIRTUAL MACHINE (JVM)
•JVM are available for almost all operating systems.
•Java bytecode is executed by using any operating
system’s JVM. Thus achieve portability.
12
JAVA RUNTIME ENVIRONMENT (JRE)
•The Java Virtual Machine is a part of a
large system i.e. Java Runtime
Environment (JRE).
•Each operating system and CPU
architecture requires different JRE. The JRE
consists of set of built- in classes, as well as
a JVM.
•Without an available JRE for a given
environment, it is impossible to run Java
software.
13
INSTALLATION AND ENVIRONMENT
SETTING
Installation
Download the latest version j2se5.0 (java 2 standard edition) from
[Link] or get it from any
other source like CD.
Note: j2se also called jdk (java development kit). You can also
use the previous versions like jdk 1.4 or 1.3 etc. but it is
recommended that you use either jdk1.4 or jdk5.0
14