CS451 Lecture 4: Introduction to Java
-
Upload
keefe-brady -
Category
Documents
-
view
23 -
download
1
description
Transcript of CS451 Lecture 4: Introduction to Java
CS451 - Lecture 41
CS451Lecture 4: Introduction to Java
Yugi Lee
STB #555(816) 235-5932
www.sice.umkc.edu/~leeyu
*Acknowledgement: This lecture is based on material courtesy of Monash University
2CS451 - Lecture 4
Why Java? Application?
• Java can support what we are interested in ... Systems characterized as those which are typically
commercially useful; Systems which allow interaction with the user; Dynamical web pages which allow interaction only
between user and page, but not page source. interaction which involves the exchange of data
between remote user and local data source;
Distributed Web-based applications.
3CS451 - Lecture 4
Why Java? What’s Java?
simple object-oriented distributed interpreted robust secure architecture-neutral
portable high performance multithreaded dynamic buzzword-compliant
language!
(The Java Language: A White Paper)
4CS451 - Lecture 4
What’s Java?
• Green Project (1990)– Consumer device operating
software
– Requirements: small size, robust, real-time performance
• Oak– Originally used C++, then
realized a new language was needed
– Original requirements same as for current language
• Java (1993)– Intended market never
eventuated
– WWW starting to takeoff
– Language design "based on" many current OO languages (e.g., C++, Eiffel, Smalltalk, Cedar/Mesa, Objective C)
• JDK 1.0 (1996), JDK 1.1, JDK1.2, JDK1.3
5CS451 - Lecture 4
What distinguishes Java from other OO languages?
The Java Virtual Machine (JVM). Code is compiled into machine independent byte code.
Like some other languages it has a garbage collector
Prevents pointer arithmetic Prevents operator
overloading
Inbuilt security Support for threads and
exceptions as part of base language.
Provides a large collection of classes that support and simplify many common programming activities
6CS451 - Lecture 4
Java - Simple
Intentionally created to be syntactically similar to C/C++ Eliminates traditionally
troublesome features of C/C++ Pointer arithmetic Multiple inheritence Implicit type coercions Explicit memory management Preprocessor
Eliminates features of C/C++
struct typedef union enum operator overloading
Features included as part of base language:
Threads Exception handling
7CS451 - Lecture 4
Java - Object-Oriented
Systems are built from sets of classes Classes are instantiated at runtime to give objects Objects communicate via messages Everything* is part of a class OO concepts supported:
Encapsulation Inheritance Polymorphism Dynamic Binding
Logical cluster of classes == package
8CS451 - Lecture 4
Java - Distributed
Network programming support built into JDK class library: TCP sockets UDP packets IP addresses URLs Security features designed into language
• Java's network programming facilities are one of the language's best features.
9CS451 - Lecture 4
Java - Interpreted
Source code is initially compiled (javac) into architecture-neutral byte-codes
Byte-codes are interpreted by the java virtual machine (java or Netscape)
Seamless linking stage JIT compilers lead to a large performance increase in
compilation and runtime execution
10CS451 - Lecture 4
Java - Robust
Strongly-typed language Compile and runtime checking No pointer arithmetic Exception handling Automatic memory management
11CS451 - Lecture 4
Java - Secure
Generally very difficult to trick Java's security mechanisms
Depends very much on the program loader (e.g., Netscape)
The SecurityManager class defines the protocol used by the program loader
12CS451 - Lecture 4
Java - Architecture-neutral/Portable
Byte-codes are architecture neutral Performance suffers by using bytecodes Primitive type sizes are explicit - not architecture
dependent Strings and characters are (16-bit) Unicode compliant GUI libraries give a native graphic library-independent
mechanism for creating quality graphical interfaces
13CS451 - Lecture 4
Java - High performance
• Interpreting leads to quicker development cycle
Depends what you compare it to "Slightly faster than VB" JITC help greatly in this respect Can use native code for mission-critical
performance sections of code
14CS451 - Lecture 4
Java - Multithreaded
Based on well-known 20 year old Hoare monitor synchronization
Thread support built into language Thread synchronization primitives supplied
• Garbage collector runs permanently as a low priority background thread
15CS451 - Lecture 4
Java - Dynamic
Class linking, layout, name resolution and object references not resolved until run-time
Runtime Type Information (RTTI) available Class class for dynamic instantiation
16CS451 - Lecture 4
The Top 10 Worst Things About Java!
1. Performance (particularly for Swing graphics)
2. No templates/generic container classes
3. Poor debugger
4. Some poor or inconsistent design decisions (naming, IO Libraries)
5. No multiple inheritance?
6. No operator overloading?
7. Doesn't run on Windows 3.1
8. Requires JVM for each machine
9. Even though claimed as stable, new releases of JDK are issued regularly.
10. Many systems slow to support new versions of JDK