Top Banner
Internet And Java Application MCA-501(N2) Course Overview Introduction Objectives give a nontechnical overview of Ja va 1. Background
58
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Intro to Java_ppt1

Internet And Java ApplicationMCA-501(N2)

Course Overview

Introduction

Objectives– give a nontechnical overview of Java

1. Background

Page 2: Intro to Java_ppt1

Contents1. Java, etc.

2. Java's Advantages

3. Java's Disadvantages

4. Some History

5. Types of Java Code

6. Java Safety

7. Core Libraries

8. Notes on J2SE Installation

Page 3: Intro to Java_ppt1

• Machine Independent • Secure • Simple• Object-Oriented• Robust• Architecture-Neutral• Portable•Network-Savvy• Interpreted and High Performance• Multithreaded• Distributed• Dynamic

Features of Java

Page 4: Intro to Java_ppt1

Language features

• simple– syntax is based on C++ (familiarity easier transition for programmers)– removed many rarely-used, confusing features

• e.g., operator overloading, multiple inheritance, automatic coercions– added memory management (reference count/garbage collection hybrid)

network-savvy extensive libraries for coping with TCP/IP protocols like HTTP & FTP Java applications can access remote URL's the same as local files

object-oriented OOP facilities similar C++, all member functions dynamically bound pure OOP – everything is a class, no independent functions*

Page 5: Intro to Java_ppt1

Language features (cont.)robust

for embedded systems, reliability is essential Java combines extensive static checking with dynamic checking

closes C-style syntax loopholes compile-time checking more effective even so, the linker understands the type system & repeats many checks

Java disallows pointers as memory accessors arrays & strings are ADTs, no direct memory access eliminates many headaches, potential problems

secure in a networked/distributed environment, security is essential execution model enables virus-free*, tamper-free* systems

downloaded applets cannot open, read, or write local files uses authentication techniques based on public-key encryption

note: the lack of pointers closes many security loopholes by itself

Page 6: Intro to Java_ppt1

Language features (cont.)architecture-neutral

want to be able to run Java code on multiple platforms neutrality is achieved by mixing compilation & interpretation

Java programs are translated into byte code by a Java compiler byte code is a generic machine code

byte code is then executed by an interpreter (Java Virtual Machine) must have a byte code interpreter for each hardware platform byte code will run on any version of the Java Virtual Machine

Alternative execution model: can define and compile applets (little applications) not stand-alone, downloaded & executed by a Web browser

portable architecture neutral + no implementation dependent features

size of primitive data types are set libraries define portable interfaces

Page 7: Intro to Java_ppt1

Language features (cont.)interpreted

interpreted faster code-test-debug cycle just-in-time compilation (classes are loaded and recompiled on demand) on-demand linking (if class/library in not needed, won't be linked)

does interpreted mean slow?

multi-threaded a thread is like a separate program, executing concurrently can write Java programs that deal with many tasks at once by defining multiple

threads (same shared memory, but semi-independent execution) threads are important for multi-media, Web applications

high-performance faster than traditional interpretation since byte code is "close" to native code than still somewhat slower than a compiled language (e.g., C++)

Page 8: Intro to Java_ppt1

Language features (cont.)dynamic

Java was designed to adapt to an evolving environment e.g., the fragile class problem

in C++, if you modify a parent class, you must recompile all derived classes in Java, memory layout decisions are NOT made by the compiler instead of compiling references down to actual addresses, the Java compiler

passes symbolic reference info to the byte code verifier and the interpreter the Java interpreter performs name resolution when classes are being linked, then

rewrites as an address thus, the data/methods of the parent class are not determined until the linker loads

the parent class code if the parent class has been recompiled, the linker automatically gets the updated

version Note: the extra name resolution step is price for handling the fragile class problem

Page 9: Intro to Java_ppt1

JDK Editions

• Java Standard Edition (J2SE) – J2SE can be used to develop client-side standalone applications or applets.• Java Enterprise Edition (J2EE) – J2EE can be used to develop server-side appli. such as

» Java servlets » Java Server Pages.

• Java Micro Edition (J2ME) – J2ME can be used to develop applications for mobile devices such as cell phones.

Page 10: Intro to Java_ppt1

1. Java, J2SE, JSDK, JDK, JRE

• There are several 'Java' names:– Java is the name of the language

• Java 2 is the current version

– the language + tools (e.g. compiler) is called J2SE, the Java 2 Standard Edition

• J2SE 1.5.0. is the current version• its also known as J2SE 5.0

continued

the samething

Page 11: Intro to Java_ppt1

• There are two version of J2SE which contain different amounts of tools:– JSDK: the full version– JRE: just enough tools to run already compile

d programs

continued

Page 12: Intro to Java_ppt1

• JSDK– stands for "Java Software Development Kit

– JDK is the old name for JDSK– don't be surprised to also see J2SDK

or Java SDK

continued

Page 13: Intro to Java_ppt1

• JSDK contains all the libraries (packages), compiler, and other tools for writing/running/debugging Java code.

• JRE = "Java Runtime System"– a cut-down version of JSDK with only the p

ackages/tools needed for running Java code

– most often used by Web browsers

Page 14: Intro to Java_ppt1

• Machine Independent • Secure • Simple• Object-Oriented• Robust• Architecture-Neutral• Portable•Network-Savvy• Interpreted and High Performance• Multithreaded• Distributed• Dynamic

Features of Java

Page 15: Intro to Java_ppt1

Language features

• simple– syntax is based on C++ (familiarity easier transition for programmers)– removed many rarely-used, confusing features

• e.g., operator overloading, multiple inheritance, automatic coercions– added memory management (reference count/garbage collection hybrid)

network-savvy extensive libraries for coping with TCP/IP protocols like HTTP & FTP Java applications can access remote URL's the same as local files

object-oriented OOP facilities similar C++, all member functions dynamically bound pure OOP – everything is a class, no independent functions*

Page 16: Intro to Java_ppt1

Language features (cont.)robust

for embedded systems, reliability is essential Java combines extensive static checking with dynamic checking

closes C-style syntax loopholes compile-time checking more effective even so, the linker understands the type system & repeats many checks

Java disallows pointers as memory accessors arrays & strings are ADTs, no direct memory access eliminates many headaches, potential problems

secure in a networked/distributed environment, security is essential execution model enables virus-free*, tamper-free* systems

downloaded applets cannot open, read, or write local files uses authentication techniques based on public-key encryption

note: the lack of pointers closes many security loopholes by itself

Page 17: Intro to Java_ppt1

Language features (cont.)architecture-neutral

want to be able to run Java code on multiple platforms neutrality is achieved by mixing compilation & interpretation

Java programs are translated into byte code by a Java compiler byte code is a generic machine code

byte code is then executed by an interpreter (Java Virtual Machine) must have a byte code interpreter for each hardware platform byte code will run on any version of the Java Virtual Machine

Alternative execution model: can define and compile applets (little applications) not stand-alone, downloaded & executed by a Web browser

portable architecture neutral + no implementation dependent features

size of primitive data types are set libraries define portable interfaces

Page 18: Intro to Java_ppt1

Language features (cont.)interpreted

interpreted faster code-test-debug cycle just-in-time compilation (classes are loaded and recompiled on demand) on-demand linking (if class/library in not needed, won't be linked)

does interpreted mean slow?

multi-threaded a thread is like a separate program, executing concurrently can write Java programs that deal with many tasks at once by defining multiple

threads (same shared memory, but semi-independent execution) threads are important for multi-media, Web applications

high-performance faster than traditional interpretation since byte code is "close" to native code than still somewhat slower than a compiled language (e.g., C++)

Page 19: Intro to Java_ppt1

Language features (cont.)dynamic

Java was designed to adapt to an evolving environment e.g., the fragile class problem

in C++, if you modify a parent class, you must recompile all derived classes in Java, memory layout decisions are NOT made by the compiler instead of compiling references down to actual addresses, the Java compiler

passes symbolic reference info to the byte code verifier and the interpreter the Java interpreter performs name resolution when classes are being linked, then

rewrites as an address thus, the data/methods of the parent class are not determined until the linker loads

the parent class code if the parent class has been recompiled, the linker automatically gets the updated

version Note: the extra name resolution step is price for handling the fragile class problem

Page 20: Intro to Java_ppt1

2. Java’s Advantages

• Productivity– object orientation– many standard libraries (packages)

• Simpler/safer than C, C++– no pointer arithmetic, has automatic garbage

collection, has array bounds checking, etc.

continued

Page 21: Intro to Java_ppt1

• GUI features– mostly located in the Swing and Abstract

Windowing Toolkit (AWT) packages

• Multimedia– 2D and 3D graphics, imaging, animations,

audio, video, etc.

continued

Page 22: Intro to Java_ppt1

• Network support– communication with other machines/apps– variety and standards:

• sockets, RMI, CORBA

– security, resource protection

• Multithreading / concurrency– can run several ‘threads’ at once

continued

Page 23: Intro to Java_ppt1

• Portablility / Platform Independence– “write once; run anywhere”– only one set of libraries to learn

• Supports native code – can integrate legacy code

• J2SE is free

continued

Page 24: Intro to Java_ppt1

• Good programming environments:– Eclipse, Blue J, JBuilder, NetBeans, Sun

One Studio– do not use them when first learning Java– http://java.coe.psu.ac.th/Tool.html

• Applets (and Java Web Start) eliminates the need for explicit software installation.

continued

Page 25: Intro to Java_ppt1

• Good for teaching computing– many important ideas in one place

• It’s new!– ~30 years since C++ introduced

Page 26: Intro to Java_ppt1

3. Java’s Disadvantages

• Java/J2SE is still being developed– many changes between versions

• Sun has not guaranteed backward compatibility of future versions of Java.– at the moment, when old-style code is

compiled, the compiler gives a “deprecation” warning, but will still accept it

continued

Page 27: Intro to Java_ppt1

• Java compilation/execution was slow, but ...– not any more: J2SE 1.5 is the same speed

as C++ (perhaps a tiny bit slower for some things)

– there are compilers to native code, but they destroy the “write one; run anywhere” idea

– the first version of Java, back in 1995, was about 40 times slower than C++

continued

Page 28: Intro to Java_ppt1

• Cross-platform testing and debugging has been a problem (due to inconsistencies)

• “Write once; run anywhere” means that some local OS features weren't supported:– e.g. right button actions under Windows– no joysticks, special keypads– this is fixed in the latest versions of Java

continued

Page 29: Intro to Java_ppt1

• Java’s security restrictions makes some code hard to write:– cannot “see” much of a local machine– newer J2SE versions make this easier

• The existing code base (in C, VB, etc.) means that people do not want to rewrite applications in Java.

continued

Page 30: Intro to Java_ppt1

• Embedded Systems– Sun Microsystems (Java’s inventor) sees this

as a major future market for Java

– J2ME (Java 2 Micro Edition) is a cut-down version of Java

– J2ME is the main programming environment for mobile devices

continued

Page 31: Intro to Java_ppt1

• Slow Internet connections– makes it difficult (and irritating) to

download medium/large size applets– e.g. GIF89a/flash files have replaced Java

animations

• Lots to learn– Java language (small) and Java libraries

(very, very large)

continued

Page 32: Intro to Java_ppt1

• There seem to be few ‘serious’ Java applications. But ...– the Java compiler (javac) is written in Java

– most custom Java applications are internal to a company

• they don’t have the high profile of major vendor software

Page 33: Intro to Java_ppt1

4. Some History

• In 1991, Sun Microsystems set up a research project to develop a language for programming ‘intelligent’ consumer electronics– e.g. video recorders, TVs, toasters

• The language was called Oak (later changed to Java). Developed by James Gosling, and others.

Page 34: Intro to Java_ppt1

• August 1993: the project was cancelled after two commercial deals fell through.

• The Web became popular during 1993.

• July 1994: Sun restarted work on Java as a Web programming language– Java contains networking features, platfor

m portability, and a small runtime system

continued

Page 35: Intro to Java_ppt1

• Java released May 1995– Netscape supported Java in Navigator 2

.0, which gave it an enormous boost

• May 1996: JDK 1.0 released.

• February 1997: JDK 1.1 released– major changes in the event model used

by the GUI; inner classes introduced

continued

Page 36: Intro to Java_ppt1

• December 1998: JDK 1.2 released– also known as Java 2– much improved GUIs (Swing), graphics

• September 2000: J2SDK 1.3 released– still known as Java 2– improved networking, sound, security

continued

Page 37: Intro to Java_ppt1

• February 2002: J2SE 1.4 released– still known as Java 2– improved I/O, GUI improvements, increase

in standard libraries (62% more classes!)

Page 38: Intro to Java_ppt1

• September 2004: J2SE 1.5 released– also known as J2SE 5.0– the language is still Java 2– new stuff: easy IO, generics, enumerated types,

autoboxing, concurrency tools, faster speed, improved monitoring/profiling /debugging

– see the "J2SE 5.0 in a Nutshell" articlehttp://java.sun.com/developer/ technicalArticles/releases/j2se15/

Page 39: Intro to Java_ppt1

Java and C++

• What C++ programmers might try to do but can’t:– Use pointers (but like we said before, everything is a

pointer), they are called unsafe code.– Include files (use packages instead)– Use global variables (although the concept of global

variables can easily be simulated)– Operator overloading– templates (although the new Java 5.0 has introduced

support for these)– Multiple inheritance (interfaces are used instead)– Destructors (nobody liked them anyways)– Could program a stack class with Objects, and then cast into

an object of another class.

Page 40: Intro to Java_ppt1

Java and C++ Contd…..

– No such thing as environment variables as there are with C/C++ and Unix because this is not OS independent.

– Exception: primitive data types such as int, float are not subclasses of Object. However, there are wrapper classes Integer, Double, etc.

– No overloading of operators (although function overloading is okay).

– No i/o operators <<, >>.– No general multiple inheritance.– No support for typedef, goto, and also does not have delete

operator.

Page 41: Intro to Java_ppt1

Which Java Should I Use?

• The latest version (September 2004) is:– Java 2, J2SE 1.5 (or 5.0)

• Textbooks that talk about JDK 1.0, JDK 1.1. should be thrown into a rubbish bin.

• Textbooks that talk about JDK 1.2, J2SDK 1.3 are fine for new Java programmers.

Page 42: Intro to Java_ppt1

5. Types of Java Code

There are two kinds of Java code:

• 1. Java applications– ordinary programs; stand-alone– they don’t run inside a browser

(but they can use Java’s GUI libraries)

continued

We will seeexamples inthe next part.

Page 43: Intro to Java_ppt1

• 2. Java applets– they run in a Web browser

– they are attached to Web pages, so can be downloaded easily from anywhere

– applets have access to browser features

Page 44: Intro to Java_ppt1

6. Java Safety

6.1. Java Bytecodes

6.2. Applet advantage/disadvantage

6.3. The Java Virtual Machine

6.4. JVM Restrictions upon Applets

6.5. Relaxing Security

Page 45: Intro to Java_ppt1

The JVM and Bytecode• Unlike C++ programs, Java programs are not compiled into

machine language• Instead they are compiled into Java bytecode• The bytecode is then interpreted by the Java Virtual Machine

(JVM) • This is the key to Java’s universality. • Any compiled Java bytecode can be

run on any valid JVM installed on

any Operating System (on any device,

not just a computer)• With C++ and other compiled languages, programs must be recompiled for each particular architecture that it needs to be run on

Page 46: Intro to Java_ppt1

6.1. Java Bytecodes

• The Java compiler (javac) generates bytecodes– a set of instructions similar to machine code– not specific to any machine architecture

• A class file (holding bytecodes) can be run on any machine which has a Java runtime environment.

Page 47: Intro to Java_ppt1

The Bytecode Advantage

Java code(.java file)

javac (Pentium)

javac (Mac)

javac (UNIX)

Java bytecode(.class file)

Java runtime (Pentium)

Java runtime (Mac)

Java runtime (UNIX)

Page 48: Intro to Java_ppt1

6.2. The Java Virtual Machine

• The Java Virtual Machine (JVM) is the Java runtime environment.– it acts as a layer between the executing byte

codes in an applet and the actual machine

– it hides variations between machines

– it protects the machine from attack by the applet

Page 49: Intro to Java_ppt1

Applet Execution with the JVM

Client Computer

Web Browser

JVM

applet applet

Web Server

downloadWeb pageand applet

Page 50: Intro to Java_ppt1

Application Execution with the JVM

Client Computer

JVM

application

• The difference is the amount of security imposed by the JVM– applets are allowed to do

a lot less than applications

Page 51: Intro to Java_ppt1

6.3. JVM Restrictions upon Applets

• An applet runs in its own memory space– it cannot access the local system’s memory– it cannot interfere with other running apps

• An applet cannot read/write to files on the local system (except to special directories).– e.g. it cannot read system files

continued

Page 52: Intro to Java_ppt1

• An applet cannot easily run local applications– e.g. system functions, DLLs

• An applet can only communicate with its home server– this restriction is configurable on the client-

side

Page 53: Intro to Java_ppt1

6.4. Relaxing Security

• Applets can be signed with trusted certificates– a browser can be configured to relax

security depending on an applet’s signature– an advanced topic

Page 54: Intro to Java_ppt1

7. Core Libraries

• Java runtime– standard I/O, networking, applets, basic windo

wing, data structures, internationalization, maths, etc.

• Java Foundation Classes– Swing GUI library, Java 2D graphics

continued

Page 55: Intro to Java_ppt1

• Security– digital signatures, message digests

• JDBC– database connectivity

• Java RMI– remote method invocation

• JavaBeans– a software component library

• and much, much more…

Page 56: Intro to Java_ppt1

8. Notes on J2SE Installation

• Add the bin path for Java to the PATH environment variable in c:\Autoexec.bat:

set path=%path%;c:\progra~1\java\jdk1.5.0\bin

• This says where the Java tools (e.g. javac) are located.

short for "program files"

Page 57: Intro to Java_ppt1

Install the Java Docs/Tutorial

• Unzip the Java documentation and tutorial files:– j2sdk-1_5_0-doc.zip

– tutorial.zip (only covers up to 1.4)

• Place them as subdirectories \docs and \tutorial below the directory jdk1.5.0

continued

Page 58: Intro to Java_ppt1

• You should add a Java menu item to the “Start” menu, which contains shortcut links to the Java documentation and tutorial.

• Test which Java you have. In a DOS window, type:> java -version