1 - Introduction To Java
1 - Introduction To Java
Introduction
COMP201 Topic 1 / Slide 2
Outline
C, C++, and Java
How Java is related to C and C++
Advantages of Java
Writing good codes in Java is easier than in C or C++
Course content
COMP201 Topic 1 / Slide 3
Strengths
– Not restrictive, especially in relation to type conversion.
– More efficient than C++ and Java.
Weaknesses:
– Not object-oriented: does not support abstraction and encapsulation
Difficult to manage in large projects.
Strengths
Improved data abstraction and encapsulation
Makes it easier to manage large projects
More extensive built-ins (standard libraries)
Weakness
Considered by many to be over-complicated
Contains all of C’s problems
COMP201 Topic 1 / Slide 5
Outline
C, C++, and Java
How Java is related to C and C++
Advantages of Java
Writing good codes in Java is easier than in C or C++
Course content
COMP201 Topic 1 / Slide 8
Advantages of Java
According to Sun’s Java White paper:
“Java is a simple, objected-oriented, distributed,
interpreted, robust, secure, architecture-neutral,
portable, high-performance, multi-threaded, and
dynamic language”.
Advantages of Java/Simple
Streamlined C language:
No typedef, union, enum, goto, comma operator
No header files
– C: list.h, list.c
– Java: List.java
No makefile
– Java compiler can figure out dependencies among
classes
COMP201 Topic 1 / Slide 10
Advantages of Java/Simple
Fixed problematic areas:
No pointers, no function pointers
Add garbage collection. Memory leaks no more
No code like this
if ( *Head == NULL ){
*Head=(NODESET *) memAllocate(sizeof(NODESET));
*(Head+5) = tmpNode;
(*Head)->next=(*Head)->prev=NULL;
}
memDeallocate( Head );
Advantages of Java/Simple
Everything is class except several primitive types
Array is a class. Cannot go over bound.
– No this
int a[5]; a[5]=0;
Advantages of Java/Object-Oriented
More so than C++.
Combine data and behavior into one unit, the object
Programs are collections of interacting, cooperating objects
Advantages of OOP
Provide strong data abstraction and encapsulation
Gives framework for design
Allows independent development and testing
Facilitates system extensions and maintenance
More opportunity for code re-use
COMP201 Topic 1 / Slide 13
Advantages of Java/Platform-Independent
C and C++ programs are compiled into object code,
Object code is directly processed by hardware processor.
Require a separate compiler for each computer platform, i.e. for
each computer operating system and the hardware set of
instructions that it is built on.
Java
Bytecodes
HotSpot Compiler Virtual
Java move locally
or through net
Machine
Compiler
Runtime System
Security manager
System to control permissions for high-level actions
Runtime verifier checks untrusted bytecode
Avoids havoc from hand-constructed bytecode
COMP201 Topic 1 / Slide 16
Advantages of Java
In Summary, writing good codes in Java is
easier than in C or C++
Outline
C, C++, and Java
How Java is related to C and C++
Advantages of Java
Writing good codes in Java is easier than in C or C++
Course content
COMP201 Topic 1 / Slide 18
Java Libraries
Java has far expanded traditional scope of a
language’s libraries
Java 2 SDK 1.4:
3,020 classes and interfaces
32,138 methods
Java Libraries
Collection of classes grouped into packages
Java equivalent of C libraries
java.lang
String, Math, Exception, Thread, Runtime, etc
java.util
Vector, Stack, hashtable, Date, Tokenizer
java.io
Varieties of input/output processing
java.net
Networking, client/server sockets, URLs
java.awt, javax.swing
Windows, buttons, drawing, images, events
COMP201 Topic 1 / Slide 20
Java Libraries
java.security
Encryption, digital signature, message digest
java.text
Formatting and parsing
java.sql
Database connectivity
java.rmi
Remote method invocation, distributed objects
Outline
C, C++, and Java
How Java is related to C and C++
Advantages of Java
Writing good codes in Java is easier than in C or C++
Course content
COMP201 Topic 1 / Slide 22
User DB
COMP201 Topic 1 / Slide 23
Course Contents
Language Basics:
Classes, objects, inheritance, interface, inner classes, exception,
I/O
Components in the following diagram
Other issues
Multithreading, security
User DB