1.8history of java java –based on c and c++ –originally developed in early 1991 for intelligent...

15
1.8 History of Java • Java Based on C and C++ Originally developed in early 1991 for intelligent consumer electronic devices • Market did not develop, project in danger of being cancelled Internet exploded in 1993, saved project • Used Java to create web pages with dynamic content Java formally announced in 1995 Now used to create web pages with interactive content, enhance web servers, applications for consumer devices (pagers, cell phones)...

Upload: michael-howard

Post on 31-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

1.8 History of Java

• Java– Based on C and C++– Originally developed in early 1991 for intelligent consumer

electronic devices• Market did not develop, project in danger of being cancelled

– Internet exploded in 1993, saved project• Used Java to create web pages with dynamic content

– Java formally announced in 1995– Now used to create web pages with interactive content,

enhance web servers, applications for consumer devices (pagers, cell phones)...

Page 2: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

1.9 Java Class Libraries

• Java programs– Consist of pieces called classes

– Classes contain methods, which perform tasks

• Class libraries– Also known as Java API (Applications Programming Interface)

– Rich collection of predefined classes, which you can use

• Two parts to learning Java– Learning the language itself, so you can create your own classes

– Learning how to use the existing classes in the libraries

Page 3: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

1.10 Other High-Level Languages

• A few other high-level languages have achieved broad acceptance– FORTRAN (FORmula TRANslator)

• Scientific and engineering applications

– COBOL (COmmon Business Oriented Language)• Used to manipulate large amounts of data

– Pascal• Intended for academic use

– BASIC• Developed in 1965 as a simple language to help novices

Page 4: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

1.11 Structured Programming

• Structured programming – Disciplined approach to writing programs

– Clear, easy to test and debug, and easy to modify

– Pascal designed to teach structured programming in universities• Not used in industrial or commercial applications

• Multitasking– Specifying that many activities run in parallel

– C and C++ only allow one activity to be performed at a time

– Java allows multithreading, where activities can occur in parallel

Page 5: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

1.12 The Internet and the World Wide Web

• The Internet– Developed 30 years ago, funded by the Department of Defense

– Originally designed to link universities, now accessible by hundreds of millions of computers

• World Wide Web– Allows users to view multimedia-based documents

– Internet has exploded• Mixes computing and communication

• Changes the way business is done

• Information instantly accessible

• We cover Java applications that use the Internet

Page 6: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

1.13 Basics of a Typical Java Environment

• Java Systems– Consist of environment, language, Java Applications

Programming Interface (API), Class libraries

• Java programs have five phases– Edit

• Use an editor to type Java program

• vi or emacs, notepad, Jbuilder, Visual J++

• .java extension

– Compile• Translates program into bytecodes, understood by Java interpreter

• javac command: javac myProgram.java

• Creates .class file, containing bytecodes (myProgram.class)

Page 7: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

1.13 Basics of a Typical Java Environment

• Java programs have five phases (continued)– Loading

• Class loader transfers .class file into memory

– Applications - run on user's machine

– Applets - loaded into Web browser, temporary

• Classes loaded and executed by interpreter with java command

• java Welcome

• HTML documents can refer to Java Applets, which are loaded into web browsers. To load,

• appletviewer Welcome.html

– appletviewer is a minimal browser, can only interpret applets

Page 8: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

1.13 Basics of a Typical Java Environment

• Java programs have five phases (continued)– Verify

• Bytecode verifier makes sure bytecodes are valid and do not violate security

• Java must be secure - Java programs transferred over networks, possible to damage files (viruses)

– Execute• Computer (controlled by CPU) interprets program one bytecode at a

time• Performs actions specified in program

– Program may not work on first try• Make changes in edit phase and repeat

Page 9: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

Program is created in the editor and stored on disk.

Compiler creates bytecodes and stores them on disk.

Class loader puts bytecodes in memory.

Bytecode verifier confirms that all bytecodes are valid and do not violate Java’s security restrictions.

Interpreter reads bytecodes and translates them into a language that the computer can understand, possibly storing data values as the program executes.

Phase 1

Phase 2

Phase 3

Phase 4

Phase 5

DiskEditor

Compiler

Class Loader

Disk

Disk

PrimaryMemory

.

.

.

.

.

.

PrimaryMemory

.

.

.

.

.

.

PrimaryMemory

.

.

.

.

.

.

Bytecode Verifier

Interpreter

Page 10: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

1.14 General Notes about Java and This Book

• Java– Powerful language

– Programming notes• Clarity - Keep it Simple• Portability - Java very portable, but it is an elusive goal

– Some details of Java not covered• http://java.sun.com for documentation

– Performance• Interpreted programs run slower than compiled ones

– Compiling has delayed execution, interpreting executes immediately• Can compile Java programs into machine code

– Runs faster, comparable to C / C++

Page 11: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

1.14 General Notes about Java and This Book

• Just-in-time compiler– Midway between compiling and interpreting

• As interpreter runs, compiles code and executes it

• Not as efficient as full compilers

– Being developed for Java

– Integrated Development Environment (IDE)• Tools to support software development

• Several Java IDE's are as powerful as C / C++ IDE's

Page 12: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

Hello World

/** * The HelloWorldApp class implements an application that * simply displays "Hello World!" to the standard output. */class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); //Display the string. }}

Page 13: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

Comments

The Java language supports three kinds of comments:

/* text */ The compiler ignores everything from /* to */. /** documentation */ This indicates a documentation comment (doc comment, for short).

The compiler ignores this kind of comment, just like it ignores comments that use /* and */. The

JDK javadoc tool uses doc comments when preparing automatically generated documentation. For more information on javadoc, see the Java tool documentation.

// text The compiler ignores everything from // to the end of the line.

Page 14: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

Applet

import java.applet.Applet;import java.awt.Graphics;

public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 50, 25); }}

Page 15: 1.8History of Java Java –Based on C and C++ –Originally developed in early 1991 for intelligent consumer electronic devices Market did not develop, project

HTML

<HTML><HEAD><TITLE> A Simple Program </TITLE></HEAD><BODY>

Here is the output of my program:<APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25></APPLET></BODY></HTML>