Java Evolution
Java was originally developed by Sun Microsystems in 1991 under the name Oak as a language for programming consumer electronics. It was later renamed to Java and became best known as a language for developing applications and applets to run on web browsers over the Internet. Key features of Java include being platform-independent, object-oriented, robust, secure, and having a rich class library. Java applications are compiled to bytecode that runs on a Java Virtual Machine, allowing them to run on any platform that supports Java.
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Dr. Rajeshree Khande :Intoduction to java
1. Java Evolution
Java Introduction
Java Features
How Java Differs from other OO languages
1RAJESHREE KHANDE
2. Java - An Introduction
Java - The new programming language developed by
Sun Microsystems (James Gosling) in 1991.
Originally called Oak.
Java Authors: James Gosling, Arthur Van Hoff, Andy
Bechtolsheim
A general-purpose object-oriented language.
Designed for easy Web/Internet applications
2RAJESHREE KHANDE
3. Java - An Introduction
Originally created for consumer electronics (TV, VCR,
Freeze, Washing Machine, Mobile Phone).
Java - CPU Independent language
Internet and Web was just emerging, so Sun turned it
into a language of Internet Programming.
It allows you to publish a webpage with Java code in it.
3RAJESHREE KHANDE
4. Year Development
1990 Sun decided to developed special software that could be used for
electronic devices. A project called Green Project created and
head by James Gosling.
1991 Explored possibility of using C++, with some updates announced
a new language named “Oak”
1992 The team demonstrated the application of their new language to
control a list of home appliances using a hand held device.
1993 The World Wide Web appeared on the Internet and transformed
the text-based interface to a graphical rich environment. The team
developed Web applets (time programs) that could run on all
types of computers connected to the Internet.
Java Milestones
4RAJESHREE KHANDE
5. Java Milestones
Year Development
1994 The team developed a new Web browsed called
“Hot Java” to locate and run Applets. HotJava
gained instance success.
1995 Oak was renamed to Java, as it did not survive
“legal” registration. Many companies such as
Netscape and Microsoft announced their support for
Java
1996 Java established itself as both
1. “the language for Internet programming”
2. a general purpose OO language.
1997 A class libraries, Community effort and
standardization, Enterprise Java, Clustering, etc..
5RAJESHREE KHANDE
6. Java Features
Familiar, Simple, Small
Object-Oriented
Platform-Independent and Portable
Compiled and Interpreted
Robust and Secure
Distributed
Multithreaded
High Performance
Dynamic and Extensible
6RAJESHREE KHANDE
7. Cont…
Familiar, Simple & Small
Java does not use Preprocessor header files,
goto statement and many others
no pointers
automatic garbage collection
rich pre-defined class library
http://java.sun.com/j2se/1.4.2/docs/api/
7RAJESHREE KHANDE
8. Cont…
Object-Oriented
Focus on the data (objects) and methods
manipulating the data
Almost every thing in Java is Object.
All functions are associated with objects
Almost all datatypes are objects (files, strings, etc.)
Potentially better code organization and reuse
8RAJESHREE KHANDE
9. Cont…
Platform-Independent and Portable
Java is portable.
1) Java Complier generates bytecode that can be
implemented on any machine.
2) The sizes of the primitive data types are always
the same
Application runs on all platforms.
9RAJESHREE KHANDE
10. Cont…
JAVA COMPILER
JAVA BYTE CODE
JAVA INTERPRETER
Windows 95 Macintosh Solaris Windows NT
(translator)
(same for all platforms)
(one for each different system)
10RAJESHREE KHANDE
12. JVM : Java Virtual Machine
CPU are capable of executing only the machine
instruction.
Different type of CPU hava different set of machine
instruction.
To enable java program to be executed on different
CPUs without modification, Java program are
complied into machine instruction that can be
understood and executed by idealized CPU.
12RAJESHREE KHANDE
13. JVM : Java Virtual Machine (Cont..)
Such CPU is called as Java virtual Machine (JVM)
Actually JVM is simulated program which is
executed on actual CPU.
13RAJESHREE KHANDE
14. Cont…
Compiled and Interpreted
Java compiler generate byte-codes, not native
machine code.
The compiled byte-codes are platform-
independent.
Java bytecodes are translated to machine
readable instructions at runtime (Java Virtual
Machine)
14RAJESHREE KHANDE
16. Compiled Languages: Java Execution
Text Editor Compiler Interpreter
Programmer
Source Code
.java file
Byte Code
.class file
Hardware and
Operating System
Notepad, vi javac java
appletviewer
netscape
16RAJESHREE KHANDE
17. Cont..
Java Compiler - Java source code (file with
extension .java) to bytecode (file with
extension .class)
Bytecode - an intermediate form, closer to
machine representation
A interpreter (virtual machine) on any target
platform interprets the bytecode.
17RAJESHREE KHANDE
18. Cont..
Porting the java system to any new platform
involves writing an interpreter.
The interpreter will figure out what the
equivalent machine dependent code to run.
18RAJESHREE KHANDE
19. Cont…
Robust and Secure
Usage in networked environments requires more
security
Provides many safeguard to ensure reliable code.
Strict compile time & run time type checking.
Memory allocation model is a major defense
Access restrictions are forced (private, public)
19RAJESHREE KHANDE
20. Cont…
Distributed
Designed as distributed lang. For creating
application on network.
Java program can access remote access remote
objects on internet
20RAJESHREE KHANDE
22. How Does Java Compares to C++
and Other OO Languages
C
C++
Java
22RAJESHREE KHANDE
23. Java better than C ?
No Preprocessor
No Global Variables
No data types struct, union and enum
No Goto ,size of and typedef
No type modifier keywords auto, extern, register,
signed and unsigned.
No Pointers
Add labeled break and continue
23RAJESHREE KHANDE
24. Rich Class Environment
Core Classes
Language support Package :
Collection of classes For Implementing Basic
features of Java (java.lang.*)
Utilities Package :
provide utility function such as date & time
(java.util.*)
Input/Output package:
Collection of class required for input/output (java.io.*)
24RAJESHREE KHANDE
25. Rich Class Environment
Networking package:
Collection of classes communication with other
computers via internet. (java.net.*)
Abstract Window Tool Kit (AWT) :
Collection of Packages that implement platform
independent GUI (java.awt.*)
Applet Package :
Set of classes allows to create applet program
(java.applet.*)
25RAJESHREE KHANDE
26. Java Applications
We can develop two types of Java programs:
Stand-alone applications
Web applications (applets)
26RAJESHREE KHANDE
27. Applications v/s Applets
Different ways to run a Java executable are:
Application-
A stand-alone program that can be invoked from
command line . A program that has a “main”
method
Applet-
A program embedded in a web page , to be run
when the page is browsed . A program that
contains no “main” method
27RAJESHREE KHANDE
28. Applets v/s Applications
Different ways to run a Java executable are
Application –Executed by the Java interpreter.
Applet- Java enabled web browser.
28RAJESHREE KHANDE
29. Significance of downloading
Applets
Interactive WWW
Flashy animation instead of static web pages
Applets react to users input and dynamically change
Display of dynamic data
WWW with Java - more than a document publishing
medium
http://www.javasoft.com/applets/alpha/applets/Stock
Demo/standalone.html
29RAJESHREE KHANDE
30. Java Development Kit
Tools in JDK Purpose
javac It is java complier. It complies java source code into the
bytecode which can be understood by JVM.
java Java Interpreter – It interprets the bytecode into machine
code & then executes it
jdb Java debugger – detect the errors in java program
appletviewer Executes the special type of java program known as
applet
javadoc Used to create documentation in HTML
javah Produces a c header file for use with special type of java
method , known as native methods
Javap Java disassembler – Helps to convert bytecode file into
java program description
30RAJESHREE KHANDE
31. Process of Building and Running
Java Programs
Text Editor
Java Source
Code
javac
Java Class File
java
Outout
javadoc
javah
jdb
HTML Files
Header Files
31RAJESHREE KHANDE
32. Let us Try Out
Building your first Java Program
32RAJESHREE KHANDE
33. Creating, Compiling, and
Running Programs
Source Code
Create/Modify Source Code
Compile Source Code
i.e., javac Welcome.java
Bytecode
Run Byteode
i.e., java Welcome
Result
If compilation errors
If runtime errors or incorrect result
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
…
Method Welcome()
0 aload_0
…
Method void main(java.lang.String[])
0 getstatic #2 …
3 ldc #3 <String "Welcome to
Java!">
5 invokevirtual #4 …
8 return
Saved on the disk
stored on the disk
Source code (developed by the programmer)
Byte code (generated by the compiler for JVM
to read and interpret, not for you to understand)
33RAJESHREE KHANDE
34. Demo program
// HelloWorld.java
class HelloWorld
{
public static void main(String args[])
{
System.out.println(“Hello World”);
}
}
34RAJESHREE KHANDE
35. Program Processing
Compilation
# javac hello.java
results is HelloInternet.class
Execution
# java HelloInternet
Hello Internet
#
35RAJESHREE KHANDE
36. public static void main
Access to all / can be accessed from
everywhere
Does not return
anything
main Method
Means the main
method is shared by all
objects in the class.
Access without object
name
36RAJESHREE KHANDE
37. System.out.println(“…”);
Out is the output stream
used to connect the
console
To print the
specific string onto
output device in
next line.
System is predefined class
to provide access to the
system
System: System refers to current java program.
Out : out refers to output device. by default it is monitor.
println : to print the specific string onto output device in
next line
OR
37RAJESHREE KHANDE
38. Program Processing
Compilation
C:> javac HelloWorld.java
results in HelloWorld.class
Execution
c:> java HelloWorld
Hello World
38RAJESHREE KHANDE
39. Fundamental structure Java prog
/* a comment */
// a comment
[package declarations]
[import statements]
class declaration
{
}
An example is given below:
import java.lang.*;
class Demo
{
public static void main(String[] args)
{
Sytem.out.println("Hello! World");
}
39RAJESHREE KHANDE
40. Simple Java Applet
//HelloWorld.java
import java.applet.Applet;
import java.awt.*;
public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString (“Hello World !”,25,
25);
}
}
40RAJESHREE KHANDE
41. Calling an Applet
<HTML>
<TITLE>
HELLO WORLD APPLET
</TITLE>
<HEAD>
THE HELLO WORLD APPLET
</HEAD>
<APPLET CODE=“HelloWorld.class” width=500
height=500>
</APPLET>
</HTML> 41RAJESHREE KHANDE
43. Class & Object
What Are Classes?
A class is a blueprint or prototype that
defines the variables and the methods
common to all objects of a certain kind.
What Is an Object?
An object is a software bundle of variables
and related methods. Software objects are
often used to model real-world objects you
find in everyday life
43RAJESHREE KHANDE
44. Class vs. Object
Specifies the
structure (the
number and types)
of its objects’
attributes — the
same for all of its
objects
Specifies the
possible behaviors
of its objects
Holds specific
values of attributes;
these values can
change while the
program is running
Behaves
appropriately when
called upon
44RAJESHREE KHANDE
45. Class vs. Object
A piece of the
program’s source
code
Written by a
programmer
An entity in a
running program
Created when the
program is running
(by the main method
or a constructor or
another method)
45RAJESHREE KHANDE
46. Classes
public class Car
{
...
}
Car.java By convention, the
name of a class (and
its source file) always
starts with a capital
letter.
(In Java, all names are case-sensitive.)
46RAJESHREE KHANDE
47. public class SomeClass
Fields
Constructors
Methods
}
Attributes / variables that define the
object’s state; can hold numbers,
characters, strings, other objects
Procedures for constructing
a new object of this class
and initializing its fields
Actions that an object
of this class can take
(behaviors)
{
Class header
SomeClass.java
import ... import statements
47RAJESHREE KHANDE
48. Classes
A class is a collection of fields (data) and methods
(procedure or function) that operate on that data.
The basic syntax for a class definition:
Bare bone class – no fields, no methods
public class Circle {
// my circle class
}
ClassName]
{
[fields declaration]
[methods declaration]
}
48RAJESHREE KHANDE
49. Classes
Classes describe the data held by each of its
objects
A class may describe any number of objects
A class may describe a single object, or even
no objects at all
49RAJESHREE KHANDE