Java and its Evolution
description
Transcript of Java and its Evolution
![Page 1: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/1.jpg)
Java and its Evolution
![Page 2: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/2.jpg)
Contents
Java Introduction Java Features How Java Differs from other OO
languages Java and the World Wide Web Java Environment Build your first Java Program Summary and Reference
![Page 3: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/3.jpg)
Java - An Introduction
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 Authors: James , Arthur Van , and others
Java is really “C++ -- ++ “
![Page 4: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/4.jpg)
Java Introduction
Originally created for consumer electronics (TV, VCR, Freeze, Washing Machine, Mobile Phone).
Java - CPU Independent language Internet and Web was just
emerging, so Sun turned it into a language of Internet Programming.
It allows you to publish a webpage with Java code in it.
![Page 5: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/5.jpg)
Sun white paper defines Java as:
Simple and Powerful Safe Object Oriented Robust Architecture Neutral and Portable Interpreted and High Performance Threaded Dynamic
![Page 6: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/6.jpg)
Java is Compiled and Interpreted
Text Editor Compiler Interpreter
Programmer
Source Code
.java file
Byte Code
.class file
Hardware and Operating System
Notepad, emacs,vi
javac
javaappletviewernetscape
![Page 7: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/7.jpg)
Total Platform Independence
JAVA COMPILERJAVA COMPILER
JAVA BYTE CODEJAVA BYTE CODE
JAVA INTERPRETERJAVA INTERPRETER
Windows 95 Macintosh Solaris Windows NT
(translator)
(same for all platforms)
(one for each different system)
![Page 8: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/8.jpg)
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.
![Page 9: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/9.jpg)
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
![Page 10: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/10.jpg)
How Does Java Compare to C++ and Other OO Languages?
![Page 11: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/11.jpg)
Overlap of C, C++, and Java
C
C++
Java
![Page 12: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/12.jpg)
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
?
![Page 13: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/13.jpg)
Java Integrates Power of Compiled Languages
and Flexibility of Interpreted Languages
![Page 14: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/14.jpg)
Java Applications
We can develop two types of Java programs: Stand-alone applications Web applications (applets)
![Page 15: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/15.jpg)
Applications v/s Applets
Different ways to run a Java executable code are:Application- A stand-alone program that
can be invoked from command line . A program that has a “mainmain” method. It is executed by the Java Interpreter.
Applet- A program embedded in a web page , to be run when the page is browsed . A program that contains no “main” method. It is executed on a Java-enabled web browser.
![Page 16: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/16.jpg)
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
![Page 17: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/17.jpg)
Process of Building and Running Java Programs
Text Editor
Java Source Code
javac
Java Class File
java
Output
javadoc
javah
jdb
HTML Files
Header Files
![Page 18: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/18.jpg)
18
Java Program Structure
A Java program consists of: One or more classes A class contains one or more methods A method contains program statements
We will explore these terms in detail
![Page 19: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/19.jpg)
19
Java Program Structure
public class MyProgram
{
}
// comments about the class
class header
class body
Comments can be placed almost anywhere
![Page 20: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/20.jpg)
20
Java Program Structure
public class MyProgram
{
}
// comments about the class
public static void main (String[] args)
{
}
// comments about the method
method headermethod body
![Page 21: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/21.jpg)
21
Hello World
public class HelloWorld
{
}
// HelloWorld.java
public static void main (String[] args){
}
System.out.println(“Hello World!”);
![Page 22: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/22.jpg)
22
Hello World
public class HelloWorld
{
}
// HelloWorld.java
public static void main (String[] args){
}
System.out.println(“Hello World!”);
Creates a “class” called HelloWorld Compiled to HelloWorld.class Classes used to define objects… later
![Page 23: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/23.jpg)
23
Hello World
public class HelloWorld
{
}
// HelloWorld.java
public static void main (String[] args){
}
System.out.println(“Hello World!”);
The “main” method is where it starts to run Ignore “public static void” and “String[]
args” for now
![Page 24: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/24.jpg)
24
Hello World
public class HelloWorld
{
}
// HelloWorld.java
public static void main (String[] args){
}
System.out.println(“Hello World!”);
Contains one “statement” The System.out.println function comes
from the Java “class library” Ends with a semicolon (all statements do)
![Page 25: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/25.jpg)
25
Compiling and Running
Create the file HelloWorld.java in a text editor
Compile: javac HelloWorld.java
Run: java HelloWorld
Output: Hello World!
![Page 26: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/26.jpg)
26
Comments
Three kinds of comments:
To simplify: comments are good
// a one-line comment/* a multi-line comment */
/** a javadoc comment */
![Page 27: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/27.jpg)
27
Reserved Words and Identifiers
Reserved words are specified by the language All Java reserved words are in the text
Identifiers are specified by a programmer Maybe you: e.g. HelloWorld Maybe someone else: e.g. println
![Page 28: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/28.jpg)
28
Declaring Variables
Syntax:
Examples: int count1, int count 2; int count = 0; String course1 = “CMPT 126”;
<variable declaration> ::= <type> <declarator>, …. ;<declarator> ::= <identifier>
<declarator> ::= <identifier> = <expression>
![Page 29: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/29.jpg)
29
Primitive Data Types in Java
Four integer types: byte, short, int, long
Two floating point types float, double
One of them is for characters char
One of them is for boolean values boolean
![Page 30: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/30.jpg)
30
Expressions and Assignment
An expression is a combination of one or more operators and operands
Arithmetic operators: +, -, *, /, % Use the normal order of operationse.g. int exp = 2 * 5 +7; count = count + 1;
count++; Boolean operators: &&, ||
![Page 31: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/31.jpg)
31
More Assignment Operators
x += y is equivalent to x = x + y
![Page 32: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/32.jpg)
32
Example: String Objects
We have already seen one object type in Java: String
A String object is a list of characterse.g. “Hello world!” or “My name is Aaron”
Can be passed to print or println Can be concatenated using the (+)
operatore.g. “Hello world! ” + “My name is Aaron” “I can also append numbers, like “ + 2
![Page 33: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/33.jpg)
33
Object Instances
We must create a new “instance” of an object to store something Each object type has a constructor (more later) Create instances using the reserved world new e.g. course = new String(“CMPT 126”);
This creates a new String in memory It stores the characters “CMPT 126” The assignment sets course to refer to
this instance
![Page 34: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/34.jpg)
34
References and Instances
String course;
new String(“CMPT 126”)
course = new String(“CMPT 126”);
course:
CMPT 126
CMPT 126course:
![Page 35: Java and its Evolution](https://reader036.fdocuments.net/reader036/viewer/2022082203/56814e95550346895dbc41a6/html5/thumbnails/35.jpg)
Summary
Java has emerged as a general purpose OO language.
It supports both stand alone and Internet Applications.
Makes the Web Interactive and medium for application delivery.
Provides an excellent set of Tools for Application Development.
Java is ubiquitous!