Вы находитесь на странице: 1из 40

Java History

• Computer language innovation and development occurs for


two fundamental reasons:
1) to adapt to changing environments and uses
2) to implement improvements in the art of programming
• The development of Java was driven by both in equal
measures.
• Many Java features are inherited from the earlier languages:
B  C  C++  Java

L 1.1
Before Java: C++

• Designed by Bjarne Stroustrup in 1979.


• Response to the increased complexity of programs and
respective improvements in the programming paradigms and
methods:
1) assembler languages
2) high-level languages
3) structured programming
4) object-oriented programming (OOP)
• OOP – methodology that helps organize complex programs
through the use of inheritance, encapsulation and
polymorphism.
• C++ extends C by adding object-oriented features.

L 1.3
Java: History
• In 1990, Sun Microsystems started a project called Green.
• Objective: to develop software for consumer electronics.
• Project was assigned to James Gosling, a veteran of classic
network software design. Others included Patrick Naughton,
ChrisWarth, Ed Frank, and Mike Sheridan.
• The team started writing programs in C++ for embedding into
– toasters
– washing machines
– VCR’s
• Aim was to make these appliances more “intelligent”.

L 1.4
Java: History (contd.)
• C++ is powerful, but also dangerous. The power and popularity of
C derived from the extensive use of pointers. However, any
incorrect use of pointers can cause memory leaks, leading the
program to crash.
• In a complex program, such memory leaks are often hard to
detect.
• Robustness is essential. Users have come to expect that Windows
may crash or that a program running under Windows may crash.
(“This program has performed an illegal operation and will be
shut down”)
• However, users do not expect toasters to crash, or washing
machines to crash.
• A design for consumer electronics has to be robust.
• Replacing pointers by references, and automating memory
management was the proposed solution.

L 1.5
Java: History (contd.)

• Hence, the team built a new programming language called Oak, which
avoided potentially dangerous constructs in C++, such as pointers,
pointer arithmetic, operator overloading etc.
• Introduced automatic memory management, freeing the programmer to
concentrate on other things.
• Architecture neutrality (Platform independence)
• Many different CPU’s are used as controllers. Hardware chips are
evolving rapidly. As better chips become available, older chips become
obsolete and their production is stopped. Manufacturers of toasters and
washing machines would like to use the chips available off the shelf, and
would not like to reinvest in compiler development every two-three
years.
• So, the software and programming language had to be architecture
neutral.

L 1.6
Java: History (contd)
• It was soon realized that these design goals of consumer electronics perfectly suited
an ideal programming language for the Internet and WWW, which should be:
 object-oriented (& support GUI)
 – robust
 – architecture neutral
• Internet programming presented a BIG business opportunity. Much bigger than
programming for consumer electronics.
• Java was “re-targeted” for the Internet
• The team was expanded to include Bill Joy (developer of Unix), Arthur van Hoff,
Jonathan Payne, Frank Yellin, Tim Lindholm etc.
• In 1994, an early web browser called WebRunner was written in Oak. WebRunner
was later renamed HotJava.
• In 1995, Oak was renamed Java.
• A common story is that the name Java relates to the place from where the
development team got its coffee. The name Java survived the trade mark search.

L 1.7
Java History

• Designed by James Gosling, Patrick Naughton, Chris


Warth, Ed Frank and Mike Sheridan at Sun Microsystems
in 1991.
• The original motivation is not Internet: platform-
independent software embedded in consumer electronics
devices.
• With Internet, the urgent need appeared to break the
fortified positions of Intel, Macintosh and Unix
programmer communities.
• Java as an “Internet version of C++”? No.
• Java was not designed to replace C++, but to solve a
different set of problems.
L 1.8
The Java Buzzwords
• The key considerations were summed up by the Java team
in the following list of buzzwords:
 Simple
 Secure
 Portable
 Object-oriented
 Robust
 Multithreaded
 Architecture-neutral
 Interpreted
 High performance
 Distributed
 Dynamic
L 1.9
• simple – Java is designed to be easy for the professional
programmer to learn and use.
• object-oriented: a clean, usable, pragmatic approach to objects,
not restricted by the need for compatibility with other languages.
• Robust: restricts the programmer to find the mistakes early,
performs compile-time (strong typing) and run-time (exception-
handling) checks, manages memory automatically.
• Multithreaded: supports multi-threaded programming for
writing program that perform concurrent computations

L 1.10
• Architecture-neutral: Java Virtual Machine provides
a platform independent environment for the execution
of Java byte code
• Interpreted and high-performance: Java programs
are compiled into an intermediate representation –
byte code:
a) can be later interpreted by any JVM
b) can be also translated into the native machine code
for efficiency.

L 1.11
• Distributed: Java handles TCP/IP protocols,
accessing a resource through its URL much like
accessing a local file.
• Dynamic: substantial amounts of run-time type
information to verify and resolve access to objects
at run-time.
• Secure: programs are confined to the Java
execution environment and cannot access other
parts of the computer.
L 1.12
• Portability: Many types of computers and operating
systems are in use throughout the world—and many
are connected to the Internet.
• For programs to be dynamically downloaded to all the
various types of platforms connected to the Internet,
some means of generating portable executable code is
needed. The same mechanism that helps ensure
security also helps create portability.
• Indeed, Java's solution to these two problems is both
elegant and efficient.

L 1.13
Java Programming Language
• Need for Java
• Java applications are:
• Character User Interface (CUI) Applications:Has access to the
system resources, such as file systems and can read and write to
files on local computers.
• Graphical User Interface (GUI) Applications: Used in the Windows
environment.
• Applets: Are small executable programs that run on a Web page
and require a Java-enabled browser, such as Internet Explorer or
Netscape Navigator.
• Servlets:Are the programs that are used to extend the functionality
of Web servers.
• Packages:Are collection of classes that can be reused by
applications and applets.
Java Programming Language (Contd.)
• Java Architecture
• Various components of Java Architecture are:
• Java programming language
• Java class file
• Java Virtual Machine (JVM)
• Java Application Programming Interface (API)
Java Programming Language (Contd.)
• Java Programming Language and class File
• The Java programming environment
Java Programming Language (Contd.)
• Java Virtual Machine (JVM)
• Components of the JVM:
• Class loader
• Execution engine
• Just In Time(JIT) compiler
Java Programming Language (Contd.)
• Java Application Programming Interface (API)
• Components of Java platform
Java Programming Language (Contd.)
• Java architecture security features:
• Compiler level security
• Byte code verifier
• Class loader
• Sandbox model
Java Programming Language (Contd.)
• Security levels in Java architecture:
Java Programming Language (Contd.)
• Bytecode is verified in two phases:
• In the first phase, the verifier checks for the structure of the .class file.
• The second level phase occurs when the Bytecode is run.The Bytecode
verifier checks the validity of classes, variables, and methods used in a
program.
Declaring Variables and Literals
• The various data types in Java are:
• Primitive or the simple data types
• Abstract or the derived data types
Declaring Variables and Literals
(Contd.)
Group Data Size Range Default
Type Value

Integer byte One byte -27 to 27–1 0


(signed)

short Two byte -215 to 215 –1 0

int Four byte -231 to 231-1 0

long Eight byte -263 to 263-1 0


Declaring Variables and Literals
(Contd.)
Group Data Size Range Default
Type Value

Floating point float Four byte 3.4e-038 to 0.0


3.4e+038

double Eight byte 1.7e-308 to 0.0


1.7e+308

Boolean boolean One bit true or false false

Character char Two byte a single character null


Declaring Variables and Literals
(Contd.)
Data type Width (Bits) Range
• Integer data types and their width and ranges

byte 8 -128 to 127

short 16 -32,768 to 32,767

int 32 -2,147,483,648 to
2,147,483,647

long 64 -9,223,372,036,854,
775,808 to 9,223,372,
036, 854,775,807
Declaring Variables and Literals
(Contd.)
• Floating point data types:
• Float:Has a range of 32 bits
• Double:Has a range of 64 bits
• Character data type:
• Has a width of 16-bits
• Has the set of standard ASCII character ranging from 0 to 127
Declaring Variables and Literals
(Contd.)
• Abstract data types:
• Data types derived from the primitive data types
• String stores letters, digits, and characters such as as /, (), :, :, $,
and #.
Declaring Variables and Literals
(Contd.)
• Keywords available in Java:

abstract boolean break byte

case catch char class

const continue default do

double else extends final

finally float for goto

if implements Import instanceof


Declaring Variables and Literals
(Contd.)
• Keywords available in Java: (Contd.)

int interface long native

new package private protected

public return short static

strictfp super switch synchronized

this throw throws transient

try void volatile while


Declaring Variables and Literals
(Contd.)
• Defining Variables and Literals:
• A variable is the name that refers to a memory location where some
data value is stored.
• Each variable that is used in a program must be declared.
Declaring Variables and Literals
(Contd.)
• Naming Conventions for Variables:
• The name of a variable needs to be meaningful, short, and without any
embedded space or symbol.
• A variable name must be unique.
• A variable name must begin with a letter, an underscore (_), or the
dollar symbol ($), which can be followed by a sequence of letters or
digits (0 to 9), ‘$’, or ‘_’ .
• A variable name should not start with a digit.
• A variable name should not contain embedded white spaces .
• A variable name should not consist of a keyword.
• A variable name in Java is case sensitive.
Declaring Variables and Literals
(Contd.)
• Types of Variables:
• Class variables
• Instance variables
• Local variables
• Static variables
• Automatic variables
Declaring Variables and Literals
(Contd.)
• Literals in Java:
• Integer literals
• Floating point literals
• Character literals
• String literals
• Boolean literals
Declaring Variables and Literals
(Contd.)
• Manipulating Variables:
• Assignment Operator
• You use the assignment operator (=) to assign a value to a
variable.
Declaring Variables and Literals
(Contd.)
Operator Operation

+ Adds two operands

- Subtracts one operand from another”

* Multiplies two operands

/ Divides two operands


Declaring Variables and Literals
(Contd.)
Operator Operation

% Calculates the modulus

++ Increments a variable

-- Decrements a variable
Using Arrays
• Arrays:
• One-dimensional arrays
• Multi-dimensional arrays
Using Arrays (Contd.)
• Memory allocation to arrays:
Summary
In this lesson, you learned:
• Java is both a language and a technology used to develop desktop and
Internet-based applications known as Java applications and applets.
• The various characteristics of Java programming language
• Simple
• Object-oriented
• Compiled and interpreted
• Portable
• Distributed
• Robust
• Secure
• Various components of the Java architecture are:
• Java programming language
• Java class file
• Java Virtual Machine
• Java Application Programming Interface (API).
Summary(Contd.)

• The JVM converts the bytecode contained in the .class file to machine object
code.
• The various data types defined in Java are:
• Integers: Include byte, short, int, and long data types.
• Floating-point numbers: Include double and float data types.
• Characters: Include char, data type.
• Boolean: Include boolean, data type.
• The built-in or the intrinsic data types in Java are known as the primitive or
the simple data types.
• The abstract data types include the data types derived from the primitive
data types.
• The keywords are the reserved words for a language, which express the
language features.
Summary(Contd.)
• A variable is the basic storage unit in Java. It is the name that refers to a
memory location where some data value is stored.
• The various types of variables are:
• Class variables
• Instance variable
• Local variables
• Static variables
• Automatic variables
• You use operators in Java to manipulate data and variables. The various
operators are assignment and arithmetic operators.
• An array is a group of variables of the same data type and referred to by a
common name. A specific element of an array can be accessed by its index.
An array is a block of memory locations.

Вам также может понравиться