You are on page 1of 52

JAVA

PROGRAMMING
CHAPTER 2
NEW SHORES
S I VA S A K T H I B
HISTORY OF JAVA
• Java - The new programming language developed by Sun
Microsystems in 1991.
• Originally called Oak by James Gosling, one of the
inventors of the Java Language.
• Java -The name that survived a patent search
• Java Authors: James , Arthur Van , and others
• Java is really “C++ -- ++ “
HISTORY OF JAVA – CONT.

Originally created for consumer Java - CPU Independent Internet and Web was just It allows you to publish a
electronics (TV, VCR, Freeze, language emerging, so Sun turned it into a webpage with Java code in it.
Washing Machine, Mobile language of Internet
Phone). For PDA Programming.
HISTORY OF JAVA – CONT.
• What’s in a name!
• Oak should support
 Platform Independent
 Extremely reliable
 Compact
HISTORY OF JAVA – CONT.
JAVA MILESTONES
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.
HISTORY OF JAVA – CONT.
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 it self 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..
HISTORY OF JAVA – CONT.
JAVA MILESTONES

Year Development
1995 “JAVA 1.0” –WRITE ONCE RUN ANYWHERE (WORA)

2006 & JAVA become open source under GNU General Public
2007 Licence(GPL)
JAVA FEATURES
SUN WHITE PAPER DEFINES JAVA AS:

SIMPLE AND SAFE OBJECT ROBUST ARCHITECTURE INTERPRETED


POWERFUL ORIENTED NEUTRAL AND AND HIGH
PORTABLE PERFORMANCE

THREADED DYNAMIC
JAVA FEATURES –
CONT.
• Familiar, Simple, Small
• Object-Oriented
• Distributed
• Platform-Independent and Portable
• Compiled and Interpreted
• Architecture Neutral
• Robust and Secure
• Multithreaded and Interactive
• High Performance
• Dynamic and Extensible
• High Performance
• Multimedia support
JAVA FEATURES – CONT.

Why JAVA is simple?


• Automatic memory allocation
• Automatic Garbage collection
• Easy syntax
• Easy to read and write
• Wide variety of APIs to make programming easy
• Replaced the multiple inheritance (C++)
• Eliminated the usage of pointer
JAVA FEATURES –
CONT.
Object-Oriented
• Java is object oriented
• Provides greater flexibility, modularity, reusability
• Class, Instantiation, Object, Properties, Behaviors
• PIE – Polymorphism, Inheritance and
Encapsulation
• Encapsulation, polymorphism, dynamic binding
• Fully Object Oriented (no stand alone methods)vs
C++
• Eliminated the usage of pointer
INHERITANCE
• Distributed Computing
 Networking capability inherently integrated into it
 HTTP and FTP – developed in Java
• Portability (Platform independence )
JAVA  WORA(Write Once Run Anywhere)
FEATURES –  C and C++-decides the precision and storage
CONT. requirements for basic datatypes(int,float e.t.c)-size of
structs violates
 C and c++-moving between platforms requires
recompilation, redesign-affects networking capabilities
COMPILED LANGUAGES
Programmer

Source Code Object Executable


Code Code
Text Editor Compiler linker
.c file .o file a.out file
Notepad, gcc
emacs,vi
JAVA IS COMPILED AND INTERPRETED
Hardware and
Programmer
Operating System

Source Code Byte Code

Text Editor Compiler Interpreter


.java file .class file
Notepad, javac java
emacs,vi appletviewer
netscape
TOTAL PLATFORM INDEPENDENCE
JAVA COMPILER
(translator)

JAVA BYTE CODE


(same for all platforms)

JAVA INTERPRETER
(one for each different system)

Windows 95 Macintosh Solaris Windows NT


ARCHITECTURE NEUTRAL & PORTABLE

• 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.


ARCHITECTURE NEUTRAL &
PORTABLE
• 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
JAVA FEATURES – CONT.

• Java is compiled and interpreted


Byte code (special set of machine instruction)is generated-can be run on any machines using
JVM-using Interpreter
• Java can be run on any machine-architectural neutral
JAVA FEATURES – CONT.

• Security
 Security as part of design
 Java compiler,interpretos,JRE carefully designed,loss of data,virus free,tamper free programs-
uses public key encryption method
• Robust
 Java is strong-strong memory allocation method,garbage collection mechanism
 Powerful exceptional handling and type checking
 JRE does many checks on byte codes
JAVA FEATURES – CONT.

• Multi threading
 capability to support multiple tasks-server to serve multiple clients,mp3 file and surf the web
• Dynamic and Extensible
 Dynamically links new class libraries, methods and objects from C and C++
• High Performance
 with interpreter inside JVM –make it slower than c and c++
 So Just In Time(JITcompiler) as a part of JVM-remembers the machine code sequence- is
introduced to improve the speed
 Java supports the multimedia –images,sounds and animation
OVERLAP OF C, C++, AND JAVA

C++

C Java
JAVA BETTER THAN C++ ?

• No Typedefs, Defines, or Preprocessor


• No Global Variables

?
• No Goto statements
• No Pointers
• No Unsafe Structures
• No Multiple Inheritance
• No Operator Overloading
• No Automatic Coercions
• No Fragile Data Types
OBJECT ORIENTED LANGUAGES -A COMPARISON

Feature C++ Objective Ada Java


C
Encapsulation Yes Yes Yes Yes
Inheritance Yes Yes No Yes
Multiple Inherit. Yes Yes No No
Polymorphism Yes Yes Yes Yes
Binding (Early or Late) Both Both Early Late
Concurrency Poor Poor Difficult Yes
Garbage Collection No Yes No Yes
Genericity Yes No Yes Limited
Class Libraries Yes Yes Limited Yes
JAVA AND THE INTERNET

• Applets-is for internet


• Cross platform compatibility
• Support to internet protocols
• Support to HTML -GUI
• Support to XML parsing-API
• Support to web services-support N-tierd enterprise application over the internet
• Support of java to mobile devices
• Support to PDA’s=Samsung,smart electrnics,Toshiba
WHAT IS WORLD WIDE WEB ?

• Web is an open-ended information retrieval system designed to be


used in the Internet wide distributed system.
• It contains Web pages (created using HTML) that provide both
information and controls.
• Unlike a menu driven system--where we are guided through a
particular direction using a decision tree, the web system is open
ended and we can navigate to a new document in any direction.
EXECUTION OF APPLETS
1 2 3 4 5
APPLET hello.class Create Accessing The browser
Development AT SUN’S Applet from creates
“hello.java” WEB tag in Unimelb.edu.au a new
AT SERVER HTML window and
SUN.COM document a new thread
and
then runs the
code

Hello Java
<app=
“Hello”> The Internet
Hello
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/StockDemo/
standalone.html
POWER OF JAVA AND THE WEB

• Deliver applications, not just information


• Eliminate porting
• Eliminate end-user installation
• Slash software distribution costs
• Reach millions of customers - instantly
JAVA ENVIRONMENT-

• Java Environment Contains


1. Java Development Kit (JDK)
2. Class Libraries part of Java Application Interface(Java API)
JAVA ENVIRONMENT-JDK(JAVA
DEVELOPMENT KIT)

• Program Develop environment for writing JAVA program


• JDK contains
1) JRE – Java Runtime Environment sits on top of operating system
2)Command Line Development tools – Compiler and debuggers
JAVA DEVELOPMENT KIT

• javac - The Java Compiler


• java - The Java Interpreter
• jdb- The Java Debugger
• appletviewer -Tool to run the applets

• javap - to print the Java bytecodes


• javaprof - Java profiler
• javadoc - documentation generator
• javah - creates C header files
STANDARD JDK TOOLS AND UTILITIES

• Basic Tools (javac, java, javadoc, apt, appletviewer, jar, jdb, javah, javap, extcheck)
• Security Tools (keytool, jarsigner, policytool, kinit, klist, ktab)
• Internationalization Tools (native2ascii)
• Remote Method Invocation (RMI) Tools (rmic, rmiregistry, rmid, serialver)
• Java IDL and RMI-IIOP Tools (tnameserv, idlj, orbd, servertool)
• Java Deployment Tools (pack200, unpack200)
• Java Plug-in Tools (htmlconverter)
• Java Web Start Tools (javaws)
• These tools are the foundation of the JDK. They are the tools you use to create and build
applications.
• Javac- The compiler for the Java programming language.
• Java- The launcher for Java applications. In this release, a single launcher is used both for
development and deployment.
• Javadoc-API documentation generator.
JDK DIRECTORY STRUCTURE
PROCESS OF BUILDING AND RUNNING JAVA
PROGRAMS
Text Editor

Java Source
javadoc HTML Files
Code

javac

Java Class File javah Header Files

java jdb

Outout
JAVA API

• API is pre written java code that can be used by other programmers to create java applications-
classes are grouped into packages
• JAVA API is set of huge number of classes and methods grouped into packages and included in
JDK
• Package should be included to write and use the classes
• Linked list in C –LxinkedList lass
JAVA VIRTUAL MACHINE

 JVM is heart of java program execution process


 JVM is part of JRE
 Interface between Java and hardware.
 Execute byte code
 JVM functions – Memory allocation,Garbage Collection,Loading class,Interpretation of byte code
 Load and Convert .class file and byte code into machine language instruction understand by
microprocessor
JVM ARCHITECTURE
OVERLAP OF JDK,JRE,JVM
PARTS OF JAVA

• Java SE : Java Standard Edition –to develop standard applications


• Java EE : Java Enterprise Edition – for enterprise business solution-Interner Banking
Application
• Java ME : Java Micro Edition –for PDA and mobile devices
JAVA SUPPORT SYSTEMS

• https://www3.ntu.edu.sg/home/ehchua/programming/howto/JDK_Howto.html
ADVANTAGE OF JAVA

• Java programs are robust


• Memory management is efficient and clear
• More secure
DISADVANTAGE OF JAVA

• Slower than C++


• Byte code generated and JVM has to convert that into equivalent machine code

You might also like