Java and its Evolution
description
Transcript of Java and its Evolution
Java and its Evolution
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
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++ -- ++ “
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.
Sun white paper defines Java as:
Simple and Powerful Safe Object Oriented Robust Architecture Neutral and Portable Interpreted and High Performance Threaded Dynamic
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
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)
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
How Does Java Compare to C++ and Other OO Languages?
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
?
Java Integrates Power of Compiled Languages
and Flexibility of Interpreted Languages
Java Applications
We can develop two types of Java programs: Stand-alone applications Web applications (applets)
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.
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
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
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
19
Java Program Structure
public class MyProgram
{
}
// comments about the class
class header
class body
Comments can be placed almost anywhere
20
Java Program Structure
public class MyProgram
{
}
// comments about the class
public static void main (String[] args)
{
}
// comments about the method
method headermethod body
21
Hello World
public class HelloWorld
{
}
// HelloWorld.java
public static void main (String[] args){
}
System.out.println(“Hello World!”);
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
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
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)
25
Compiling and Running
Create the file HelloWorld.java in a text editor
Compile: javac HelloWorld.java
Run: java HelloWorld
Output: Hello World!
26
Comments
Three kinds of comments:
To simplify: comments are good
// a one-line comment/* a multi-line comment */
/** a javadoc comment */
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
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>
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
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: &&, ||
31
More Assignment Operators
x += y is equivalent to x = x + y
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
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
34
References and Instances
String course;
new String(“CMPT 126”)
course = new String(“CMPT 126”);
course:
CMPT 126
CMPT 126course:
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!