WDD Lec 02
WDD Lec 02
Lecture 2
Intro to Java
Topics We Will Cover Today
History of Java
Why Java ?
Some Sample Java Based Applications
Writing a Basic Java Program
Java Program Development and Execution Steps
History
Java
Based on C and C++
Developed in 1991 for intelligent consumer electronic devices
Green Project (According to Gosling, "the goal was ... to build
a system that would let us do a large, distributed,
heterogeneous network of consumer electronic devices all
talking to each other." )
James Gosling Modified C++
Named Oak then Java
History….
Platform independent
Interpreted Language
Intermediate Code (Byte Code)
Reliable
Multiple inheritance and Operator overloading
removed
No Pointers because of security reasons
Built in network support
History…
Internet exploded in 1993, saved project
Reliability
Security
Platform Independence
Contrast to ActiveX
Rich Set of Libraries
Multithreading
Swing
Regular Expression
NET
SQL
Util
Serialization …………….
Java Programmer Efficiency
Faster Development
More programmer friendly
Less error prone
OOP
Easier to manage large development projects
Robust memory system
No pointer arithmetic and manual memory
management. Garbage collector!
Libraries
Re-use of code
Disadvantages
Java performance IS slower than C/C++
Tradeoff between development time vs. run time
Additional checks in Java which make is secure and
robust and network aware etc, all have a small cost.
BUT
JIT compilation and HotSpot
Dynamic compilation of bytecode to native code at
runtime to improve performance
HotSpot optimizes code on the fly based on dynamic
execution patterns
Can sometimes be even faster than compiled C code!
System.out.println("Hello World!"); }
}
Compiling and Running
the program
Save this file in some directory and compile it
using
javac HelloWorldApp.java
1. Edit
.java extension
2. Compile
javac command: javac MyProgram.java
java command
To load,
appletviewer Welcome.html
OR
java MyProgram
Java Program Development and
Execution Steps…
4. Verify
Bytecode verifier makes sure bytecodes are valid
and do not violate security
5. Execute
Computer interprets program one bytecode at a
time
Performs actions specified in program
Program is created in
Phase 1 Editor Disk the editor and stored
on disk.
Compiler creates
Phase 2 Compiler Disk bytecodes and stores
them on disk.
Primary
Memory
Class Loader
Phase 3
Class loader puts
bytecodes in memory.
Disk
..
..
..
Primary
Memory
Bytecode Verifier
Phase 4 Bytecode verifier
confirms that all
bytecodes are valid
and do not violate
Java’s security
.. restrictions.
..
..
Primary
Interpreter Memory Interpreter reads
Phase 5 bytecodes and
translates them into a
language that the
computer can
understand, possibly
.. storing data values as
.. the program executes.
..
Understanding Basics
Naming Conventions
MyClass
myMethod()
myVariable
MY_CONSTANT