Top Banner
1
72

1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

Dec 27, 2015

Download

Documents

Sarah Hart
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: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

1

Page 2: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

2

is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

Page 3: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

3

You can use Java to write computer applications of numbers, process words, play games, store data or do any of the thousands of other things computer software can do. Java is most similar to C and C++. The special programs called Applets that can be downloaded from the Internet and played safely within a web browser.

Page 4: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

4

Page 5: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

5

You may wonder how Sun’s

engineers were able to develop such

a powerful software development

environment and surpass all known

programming languages.

The origins of Java trace back to

1991, when Sun was investigating

consumer electronics products.

Page 6: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

6

James Gosling, the father of Java,

was intent on building a low-cost,

hardware-independent software

platform using C++. For a number of

technical reasons, C++ was

dropped, and a new language, called

Oak, was developed, based on C++,

but eliminating its shortcomings.

Page 7: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

7

Oak was used to develop a small

electronics device called “Star 7”. By

1994 the Web emerged, Oak was

renamed Java, Java was used as

the basis for a Web browser, called

WebRunner. WebRunner was

successfully demonstrated, and the

Java/HotJava project took off.

Page 8: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

8

HotJava, Java, and the Java

documentation and source code were

made available over the Web, as an

alpha version, in early 1995.

Initially Java was hosted on SPARC

Solaris, and then on Windows NT.

In the summer of 1995, Java was

ported to Windows 95 and Linux.

Page 9: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

9

In the fall of 1995 the Java Beta 1

version was released through Sun's

Web site, and Java support was

introduced in the Netscape 2.0

browser.

In December 1995 the Java Beta 2

version was released, and JavaScript

was announced by Sun and Netscape.

Page 10: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

10

Java's success became inevitable

when, in early December, both

Microsoft and IBM announced their

intention to license Java technology.

On January 23, 1996, Java 1.0 was

officially released and made

available for download over the

Internet.

Page 11: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

11

Page 12: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

12

1- Java is a Platform

2- Java is Simple

3- Java is Object-Oriented

4- Java is Platform Independent

5- Java is Safe

Page 13: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

13

6- Java is High Performance

7- Java is Multi-Threaded

8- Java is Dynamically linked

9- Java is Garbage Collected

10- Network Facilities

Page 14: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

14

JAVA IS A PLATFORM

Java is a platform for application development. A platform is a loosely defined computer industry that typically means some combination of hardware and system software that will mostly run all the same software.

Page 15: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

15

Computer programs are very

closely tied to the specific hardware

and operating system they run. A

Windows program will not run on a

computer that only runs DOS. A

Mac application can't run on a Unix

workstation and so on.

Page 16: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

16

Java solves the problem of platform-

independence by using BYTECODE.

The Java compiler does not produce

native executable code for a

particular machine like a C compiler

would. Instead it produces a special

format called BYTECODE.

Page 17: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

17

The interpreter reads the

BYTECODE and translates it into

the native language of the host

machine. Since the BYTECODE is

completely platform independent,

compiler and most of the class

libraries are written in Java

Platform.

Page 18: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

18

All these pieces, the javac

(Compiler), the java (Interpreter),

the Java Programming Language,

and more are collectively referred

to as Java Platform.

Page 19: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

19

JAVA IS SIMPLE

Java was designed to make it much

easier to write bug free code. The

most important part of helping

programmers write bug-free code is

keeping the language simple.

Page 20: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

20

About half of the bugs in C and C+

+ programs are related to Memory

Allocation and Deallocation.

Therefore the second important

addition Java makes to providing

bug-free code is Automatic memory

allocation and deallocation.

Page 21: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

21

JAVA IS OBJECT-ORIENTED

In object-oriented programs data is

represented by objects. Objects

have two sections, fields (instance

variables) and methods. Fields tell

you what an object is. Methods tell

you what an object does.

Page 22: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

22

Object oriented programming have a number of advantages including Simpler, easier to read programs, More efficient reuse of code, Faster time to market and More powerful, error-free code.

Object-oriented language C++ is a complex, difficult language.

Page 23: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

23

JAVA IS PLATFORM INDEPENDENT

Java is compiled to an intermediate form called BYTECODE. A Java program never really executes natively on the host machine. Rather a special native program called the Java interpreter reads the BYTECODE

Page 24: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

24

The BYTECODES are precisely defined and remain the same on all platforms.

In Java everything is guaranteed. However the Virtual Machine (VM) itself and some parts of the class library must be written in native code.

Page 25: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

25

JAVA IS SAFEMost notably there are no Pointers in Java. Java programs cannot access optional addresses in memory. All memory access is handled behind the scenes by the trusted runtime environment. Furthermore Java performs strong type checking.

Page 26: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

26

JAVA IS DYNAMICALLY LINKED

Java source code is divided into .java files, roughly one per each class in your program. The compiler compiles these into .class files containing BYTECODE. Each .java file generally produces exactly one .class file.

Page 27: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

27

The compiler searches the current directory and directories specified in the CLASSPATH environment variable to find other classes explicitly referenced by name in each source code file.

Furthermore, Java .class files tend to be quite small, a few kilobytes at most.

Page 28: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

28

JAVA IS GARBAGE COLLECTED

You do not need to explicitly allocate or deallocate memory in Java. Memory is allocated and reclaimed by the Garbage Collector when it is no longer needed.

Page 29: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

29

There are constructors and these

do allocate memory but this is

transparent to the programmer.

Most Java virtual machines

(JVM) use an inefficient, mark

and sweep garbage collector.

Page 30: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

30

NETWORK FACILITIES

Java has an extensive library of routines for handling easily with TCP/IP protocols like HTTP and FTP. This makes creating network connections much easier than in C or C++. Java applications can open and access objects across the net via URLs same as local file access system.

Page 31: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

31

JAVA vs C++

1. No Preprocessor #define in Java.

2. No Pointers in Java.

3. No Structures and Unions in Java.

4. No Multiple Inheritance in Java.

Page 32: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

32

5. No need to make null terminated characters array for Strings Java have built in support for Strings.

6. No goto statement in Java.

7. No operator overloading in Java.

8. No Global Functions in Java.

9. No Global Variables in Java.

Page 33: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

33

Page 34: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

34

JAVA’s main strength is its unique architecture. Java provides facilities of networking as well as at the same time works on a wide range of platforms.

Page 35: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

35

Most compilers produce

machine code (understood

by the central processor).

Some produce intermediate

code (not understood by the

central processor).

Page 36: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

36

But, Java compiler generates system architecture independent BYTECODES easy to translate, into low-level language. Java BYTECODE executed by interpreter.

Page 37: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

37

BYTECODE is also interpreted within a browser. With most programming languages, you either COMPILE or INTERPRET a program so that you can run it on your computer.

Page 38: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

38

The Java programming language is unusual in that a program is both compiled and interpreted.

With the compiler, first you translate a program into an intermediate format called

Page 39: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

39

JAVA BYTECODES the platform-independent codes interpreted by the interpreter on the Java platform. The interpreter parses and runs each Java BYTECODE instruction on the computer.

Page 40: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

40

Compilation happens just once; interpretation occurs each time the program is executed.

Page 41: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

41

The BYTECODES can be executed by only a Java Virtual Machine (JVM), which is usually implemented in software rather than hardware.

Page 42: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

42

You can think of Java

BYTECODES as the

machine code instructions

for the Java Virtual

Machine.

Page 43: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

43

Java BYTECODES help make

(write once, run anywhere)

possible.

Page 44: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

44

It means that as long as a computer has a Java virtual machine (JVM), the same program written in the Java programming language can run on Unix, Linux, Windows 2000 or on a Solaris workstation.

Page 45: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

45

Page 46: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

46

To execute Java BYTECODES, the VM uses a CLASS LOADER to load the BYTECODES from a disk or a network. Each class file is checked by a BYTECODE VERIFIER

Page 47: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

47

that ensures the class is formatted correctly and will not corrupt memory when it is executed. The execution unit of the VM is an INTERPRETER which interpret the bytecode.

Page 48: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

48

Page 49: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

49

Page 50: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

50

A Platform is the hardware or software environment in which a program runs.

We know about some of the most popular platforms like Windows 2000, Linux, Solaris, and MacOS.

Page 51: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

51

Java Platform Components

1- The Java Virtual Machine (JVM)

2- The Java Application Programming Interface (Java API)

Page 52: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

52

The JVM is the base for

the Java platform and is

ported onto various

hardware-based platforms.

Page 53: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

53

The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.

Page 54: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

54

The Java API is grouped

into libraries of related

classes and interfaces;

these libraries are known

as packages.

Page 55: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

55

Page 56: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

56

PHASE 1 (WRITE)

Program is created in the editor(like Notpad) and stored on disk with an extension of .java (filename.java).

Page 57: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

57

PHASE 2 (COMPILE)

Compiler creates

BYTECODES and stores

them on disk by using an

executable program

(javac.exe).

Page 58: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

58

The compiled BYTECODE file has an extension of .class. The filename.java produces another file filename.class.

Page 59: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

59

Syntax:

C:\> javac filename.java

Page 60: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

60

PHASE 3 (LOAD)Class loader puts BYTECODES into memory before execution.There are two types of programs in Java

Page 61: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

61

APPLICATIONS

A program that is stored and executed from the user’s local computer.Applications are executed using the Java Interpreter with a utility “JAVA.EXE”.

Page 62: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

62

APPLETS

A small program that is stored on a remote computer (that is accessed via World Wide Web (WWW) Browser).

Page 63: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

63

Applets are loaded from a remote computer into the browser of user’s local machine, executed in local browser and discarded when execution completes.

Page 64: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

64

Applets also can be viewed

by a utility called

“APPLETVIEWER.EXE”

Page 65: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

65

Applets (.class) files are embedded into HTML pages using <APPLET> Tag and that HTML page can be viewed in the browser or appletivewer.

Page 66: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

66

Syntax for Applet Tag

<Applet code=“filename.class”

height=200

width=300>

</Applet>

Page 67: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

67

Syntax for Application

C:\> java filename.class

Page 68: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

68

Syntax for Applet

C:\> appletviewer filename.html

Page 69: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

69

Page 70: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

70

JDK is a complete set of tools for java development, testing, documentation, and execution of java programs and applets. It provides the followings important programs.

Page 71: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

71

javac Java Compiler

java Java Interpreter

javadocDocumentation Generator

appletviewer Applet viewer

Page 72: 1. 2 is high level programming language like C++, Visual Basic, developed by James Gosling and Patrick Naughton at Sun Microsystems in 1991.

72

When you install the latest version of JDK which is JDK1.6 on C:\ drive, All these programs are available in the following path.

C:\program files\jdk1.6.0_14\bin