Java Technologies 1
Java Technologies 1
Programming Language
As a programming language, Java can create all kinds of applications that you could create using any conventional programming language.
A Development Environment
As a development environment, Java technology provides you with a large suite of
tools: A compiler (javac) An interpreter (java) A documentation generator (javadoc) A class file packaging tool and so on...
MIT School of Telecom Management 6
Java Features
Some features of Java: The Java Virtual Machine Garbage Collection Code Security
Java Virtual Machine (JVM) an imaginary machine that is implemented by emulating software on a real machine provides the hardware platform specifications to which you compile all Java technology code Bytecode a special machine language that can be understood by the Java Virtual Machine (JVM) independent of any particular computer hardware, so any computer with a Java interpreter can execute the compiled Java program, no matter what type of computer the program was compiled on
MIT School of Telecom Management 9
Garbage Collection
10
Code Security
Code security is attained in Java through the implementation of its Java Runtime Environment (JRE).
JRE
runs code compiled for a JVM and performs class loading (through the class loader), code verification (through the bytecode verifier) and finally code execution
MIT School of Telecom Management 11
Code Security
Class Loader
responsible for loading all classes needed for the Java program adds security by separating the namespaces for the classes of the local file system from those that are imported from network sources After loading all the classes, the memory layout of the executable is then determined. This adds protection against unauthorized access to restricted areas of the code since the memory layout is determined during runtime
MIT School of Telecom Management 12
Code Security
Bytecode verifier
tests the format of the code fragments and checks the code fragments for illegal code that can violate access rights to objects
13
14
15
16
1 2
History of Java
In the early 1990's, putting intelligence into home appliances was thought to be the next "hot" technology. Examples of intelligent home appliances:
Coffee pots and lights that can be controlled by a computer's programs. Televisions that can be controlled by an interactive television device's programs.
Anticipating a strong market for such things, Sun Microsystems in 1991 funded a research project (code named Green) whose goal was to develop software for intelligent home appliances. An intelligent home appliance's intelligence comes from its embedded processor chips and the software that runs on the processor chips. Appliance processor chips change often because engineers continually find ways to make them smaller, less expensive, and more powerful. To handle the frequent turnover of new chips, appliance software must be extremely portable.
17
History of Java
Originally, Sun planned to use C++ for its home appliance software, but they soon realized that C++ was less than ideal because it wasn't portable enough and it relied too heavily on hard-to-maintain things called pointers. Thus, rather than write C++ software and fight C++'s inherent deficiencies, Sun decided to develop a whole new programming language to handle its home appliance software needs. Their new language was originally named Oak (for the tree that was outside project leader James Gosling's window), but it was soon changed to Java. When the home appliance software work dried up, Java almost died before being released. Fortunately for Java, the World Wide Web exploded in popularity and Sun realized it could capitalize on that.
18
History of Java
2 3
Web pages have to be very portable because they can be downloaded onto any type of computer. What's the standard language used for Web pages? Java programs are very portable and they're better than HTML in terms of providing user interaction capabilities. Java programs that are embedded in Web pages are called applets. Although applets still play a significant role in Java's current success, some of the other types of Java programs have surpassed applets in terms of popularity. In this course, we cover Standard Edition (SE) Java applications. They are Java programs that run on a standard computer a desktop or a laptop, without the need of the Internet.
19
History of Java
Year 1990 Development Sun decided to developed special software that could be used for electronic devices. A project called Green Project created and head by James Gosling. Explored possibility of using C++, with some updates announced a new language named Oak
1991
1992
The team demonstrated the application of their new language to control a list of home appliances using a hand held device.
The World Wide Web appeared on the Internet and transformed the text-based interface to a graphical rich environment. The team developed Web applets (time programs) that could run on all types of computers connected to the Internet.
MIT School of Telecom Management 20
1993
History of Java
Year 1994 Development The team developed a new Web browsed called Hot Java to locate and run Applets. HotJava gained instance success. Oak was renamed to Java, as it did not survive legal registration. Many companies such as Netscape and Microsoft announced their support for Java Java established itself it self as both 1. the language for Internet programming 2. a general purpose OO language. A class libraries, Community effort and standardization, Enterprise Java, Clustering, etc..
1995
1996
1997
21
History of Java
Year
1998 1998 2004 2006 2007 2010
22
Simple
fixes some clumsy features of C++ no pointers automatic garbage collection rich pre-defined class library
Object oriented
focus on the data (objects) and methods manipulating the data all functions are associated with objects almost all datatypes are objects (files, strings, etc.) potentially better code organization and reuse
23
Interpreted
java compiler generate byte-codes, not native machine code the compiled byte-codes are platform-independent java bytecodes are translated on the fly to machine readable instructions in runtime (Java Virtual Machine)
Portable(Platform Independence )
same application runs on all platforms the sizes of the primitive data types are always the same the libraries define portable interfaces The Write-Once-Run-Anywhere
24
Reliable
extensive compile-time and runtime error checking no pointers but real arrays. Memory corruptions or unauthorized memory accesses are impossible automatic garbage collection tracks objects usage over time
Secure
usage in networked environments requires more security memory allocation model is a major defense access restrictions are forced (private, public)
25
Multithreaded
multiple concurrent threads of executions can run simultaneously utilizes a sophisticated set of synchronization primitives (based on monitors and condition variables paradigm) to achieve this
Dynamic
java is designed to adapt to evolving environment libraries can freely add new methods and instance variables without any effect on their clients interfaces promote flexibility and reusability in code by specifying a set of methods an object can perform, but leaves open how these methods should be implemented can check the class type in runtime
MIT School of Telecom Management 26
Robust
Exception handling built-in, strong type checking (that is, all data must be declared an explicit type), local variables must be initialized.
Architecture Neutral
The growing popularity of networks makes developers think distributed. In the world of network it is essential that the applications must be able to migrate easily to different computer systems. Not only to computer systems but to a wide variety of hardware architecture and Operating system architectures as well.
27
JAVA INTERPRETER
(one for each different system)
Windows XP
Macintosh
Solaris
Linux
28
Java Syrup
Java Capsules
Injectable Java
Java HairOil
29
Quiz Questions
1. a) b) c) Pseudocode uses precise computer syntax. compiles into object code. is often used when writing an algorithm.
2. Java programs can be embedded in Web pages, and such programs are called a) applets b) applications c) operating systems
30
real numbers
two values: true and false a single character
Consider a byte:
1 byte = 8 bits Each bit has two possibilities: 0 or 1 28 = 256 Thus, a byte can have any one of 256 values
short 2
int
long
-263=-9,223,372,036, 854,775,808
263-1=9,223,372,036, 854,775,807
34
= 48 1 = 49 A = 65 a = 97
35
is and || is or ! is not
MIT School of Telecom Management 36
Identifiers
Identifiers are names for variables, classes, etc. Good ones are compact, but inidicate what they stand for
Or too short
Keywords
// method main(): application entry point public static void main(String[] args) { System.out.print("I think there is a world market for"); System.out.println(" maybe five computers."); System.out.println(" Thomas Watson, IBM, 1943."); }
}
MIT School of Telecom Management 38
Capitalization
is different
recommended, though!
39
Defining variables
int
More on variables
d = 4.3;
Assignment operator =
Allows
Consider
int j = 11; j = 1985;
MIT School of Telecom Management 42
= 5; System.out.println (x);
Variable initialization
Consider the following code: int x; System.out.println(x); What happens? Error message:
variable
Constants
Expressions
When
Question on expressions
Does the following statement compute the average of double variables a, b, and c? Why or why not?
double average = a + b + c / 3.0;
47
Java operators
The following are the common operators for ints: +-/*% Division is integer division 6 / 2 yields 3 7 / 2 yields 3, not 3.5 Because everything is an int, the answer is an int Modulus is % Returns the remainder 7 % 2 yields 1 6 % 2 yields 0 Floats and doubles use the same first four operators +-/* 7.0 / 2.0 yields 3.5 7.0 / 2 yields 3.5 7 / 2.0 yields 3.5 7 / 2 yields 3
MIT School of Telecom Management 48
Java operators
is AND
Only true when both operands are true true && true yields true false && true yields false True when either of the operands (or both) are true true || false yields true false || false yields false Changes the value !true yields false !false yields true
MIT School of Telecom Management 49
||
is OR
is NOT
Functions
In Java, functions are called methods Think of mathematical functions:
Hello World!
Lets consider how to write this program. What would be the input? What would be the output? What would the algorithm look like? Nothing Hello World! Display the text Hello World! on the screen.
51
Here is the complete Java code for the Hello World! program. Lets look at it line by line.
MIT School of Telecom Management 52
54
The text beginning with // at the right side of some lines are single line comments.
They are also ignored by the Java compiler and not executed.
MIT School of Telecom Management
55
uses the Java keywords public and class keywords are displayed in blue by most IDEs
MIT School of Telecom Management 56
identifies the name of this class or program HelloWorld is the class name in this program
MIT School of Telecom Management 57
Lines 8 through 13 are called the class body. The class body begins with a left curly brace ( { )
on the line after the class header. The class body ends with a right curly brace ( } ) on the last line of the program.
MIT School of Telecom Management 60
Lines 10 through 12 are called a method body. Like a class body, a method body is enclosed by
curly braces. These are indented to improve readability.
MIT School of Telecom Management 64
65
68