Java Introductrion - Department of Computer and Information Science

Download Report

Transcript Java Introductrion - Department of Computer and Information Science

Department of Computer and Information Science,
School of Science, IUPUI
Introduction to Java
- History and Background
Dale Roberts, Lecturer
Computer Science, IUPUI
E-mail: [email protected]
Dale Roberts
Programming Languages
1. Machine languages (machine dependent)
Native tongue of a particular kind of computer. Each
instruction is a binary string. The code is used to indicate
the operations to be performed and the memory cells to be
addressed. This form is easiest form of computers to
understand, but is most difficult for a person to understand.
Strings of numbers giving machine specific instructions
Example: +1300042774
+1400593419
+1200274027
Dale Roberts
Programming Languages (cont.)
2. Assembly languages (machine dependent)
English-like abbreviations representing elementary computer
operations (translated via assemblers)
Again specific to only one type of computer. Uses descriptive
names for operations and data, e.g. , “LOAD value”, “ADD
delta”, “STORE value”. Assemblers will translate these to
machine
languages.
Intermediate
level.
Somewhat
descriptive, but basically following the machine instructions.
Example:
LOAD
ADD
STORE
BASEPAY
OVERPAY
GROSSPAY
Dale Roberts
Programming Languages (cont.)
3. High-level languages (machine independent)
Codes similar to everyday English
High-level languages: Write program instructions called statement
that resemble a limited version of English. e.g., the statement
“value = value + delta”. Portable, meaning it can be used on
different types of computers without modifications. Compilers
translate them to machine languages. Examples are FORTRAN,
PASCAL, COBOL, C, BASIC, C++, JAVA etc.
Use mathematical notations (translated via compilers)
Example:
grossPay = basePay + overTimePay
a
Before b
Example:
Statement:
a= a + b
a
After
Dale Roberts
b
10
7
17
7
Java
A programming language specifies the words
and symbols that we can use to write a program
A programming language employs a set of rules
that dictate how the words and symbols can be
put together to form valid program statements
The Java programming language was created by
Sun Microsystems, Inc.
It was introduced in 1995 and it's popularity has
grown quickly since
Dale Roberts
A Short History
1990 – Sun Microsystems begin Project Green to create a single platform
(hardware and software) that could be used on all consumer electronic
devices from video games to remote controls. The language was code
named Oak, and the company First Person was created to sell it.
1993 – Mosiac was released which provided a graphical user interface to
the previously text-oriented internet. The product eventually became
NetScape and the graphical interface became known as the world wide
web.
1994 – First Person incorporated internet-support and switched focus from
consumer electronics to providing a language-based operating system that
could deliver multimedia over the world wide web. Renamed to Java (due
to copyright infringement), the language allowed programmers to create
“applets” that could be transmitted and run over the internet. [No need to
run setup programs to install new software.] Company gave away rights to
use Java to anyone.
1995 – Sun allowed Netscape to incorporate its Java Virtual Machine into
its browser. This allowed java programs compiled into byte-code to be
transmitted over the internet to client machine and to execute in a secure
environment.
1996 – JavaSoft continues to support language.
Dale Roberts
Semantic Gap
A “semantic gap” exists between the amount of
information conveyed in assembly language v high level
languages. Consider the following C single statement:
x = x + 3;
This single statement may require many assembly
language statements (operations):
Load memory location 24 into accumulator
Add a constant 3 to the accumulator
Store accumulator in memory location 24
The number of executable statement expands greatly
during the translation process from a high level
language into assembly language.
Dale Roberts
Interpretation vs Compilation
C++ Source (*.c)
Java Source (*.java)
(machine independent)
Java Compiler
C++ Compiler
Byte-code (*.class)
(machine independent)
Java Virtual
Machine
Client Platform
(hardware/operating
system)
Client Platform
(hardware/operating
system)
Dale Roberts
(machine dependent)
Interpretation vs Compilation
Java is compiled into bytecode that is portable across
different platforms
(hardware/operating system
combinations).
Byte-code is interpreted by a
Java Virtual Machine
executing on each platform.
C++ is compiled into native
machine instructions for each
platform.
C++ is executed directly by
the platform
Interpreted code runs
between 3 and 18 times
slower than compiled code.
Dale Roberts
JIT Compilers
The trade-off in execution speed can be mitigated by adding a justin-time (JIT) compiler to the virtual machine.
Preserves portability, achieves near native performance after first
references
Compiling “on-the-fly” makes initial run slower.
Dale Roberts
JIT Compilers
The basic idea is to wait until right before you execute to compile.
Interpreter suffer because they can only see one instruction at a
time whereas a JIT can factor out thread locks and so on and some
safety checks.
JITs cannot do lots of heavy optimizations because they're
execution time is including in the perceived execution time of your
program. On the other hand, they can tailor code generation to a
specific processor instead of, for example, a generic 386 processor.
JITs work on a method by method basis. Because some code is not
executed, don't compile it. Initially, dispatch table filled with
pointers to a compiler not the actual Java bytecodes. After
compiling, the dispatch table is fixed up to point to the newly
compiled code.
Dale Roberts
Differences between Java and C++
C++ was original programming language. Java is designed to be
similar to C++ but removes complexities that Sun considered
problematic. Java is intended to be simpler to learn with less
extensive training required that C++.
Low-level syntax is identical to C and C++: primitive data types, if,
while, loop, switch, etc.
No pre-processing. No separation of class definitions from class
implementations. No header files.
No user-defined operator overloading.
Explicit conversion from intrinsic types (int, float, double) to
reference types (Integer, Float, Double).
No support for pass-by-value or pass-by-reference. All objects are
reference types, all intrinsic types are pass-by-value, except arrays.
Clone method supplied to make a “shallow” copy.
Dale Roberts
Differences between Java and C++
No multiple inheritance. Replaced with multiple interfaces, an
Abstract Class definition.
No implicit type conversion that would lose precision.
No pointers. No ability to reference memory outside an array. No
memory leakage (built-in garbage collection). No pointer arithmetic.
Pure object-oriented. Removed mixture of C-style global functions
with C++ member functions. No friend functions.
System memory management. No dangling pointers. Old objects
disposed of automatically.
Extensive security is built into the bytecode transmission to the
client, and within run-time checks with the Java Virtual Machine.
Dale Roberts
Development Environments
There are many programs that support the development of
Java software, including:
Sun Java Development Kit (JDK)
Sun NetBeans
IBM Eclipse, GNU Eclipse
Borland JBuilder
MetroWerks CodeWarrior
BlueJ
jGRASP
Though the details of these environments differ, the basic
compilation and execution process is essentially the same
Dale 1-14
Roberts
Acknowledgements
http://java.sun.com/docs/books/tutorial/getStarted/TOC.html
Pearson Education, Lewis and Loftus.
Deitel, Java How to Program
http://www.cs.wustl.edu/~plezbert/contcom/thesis/node6.html
http://www.cs.usfca.edu/~parrt/course/652/lectures-Spring2004/language.impl.overview.pdf
http://ei.cs.vt.edu/~history/Youmans.Java.html
Dale Roberts