Java Programming


What is Java?

It is a programming language Developed by Sun Microsystems (James Gosling).

It is a general-purpose object-oriented language.

It is Based on C/C++

It is widely accepted by developers.

Designed for simple Web/Internet applications.

Java Features

* Simple

Fixes some clumsy features of C++

* Object oriented

Focus on the data (objects) and methods manipulating the data.

* Interpreted

Java compiler generate byte-codes, not native machine code.

* Portable

Same application runs on all platforms.

* Reliable

Extensive compile-time and runtime error checking.

* Secure

Usage in networked environments requires more segurity.

* Multithreaded

Multiple concurrent threads of executions can run simultaneously.

* Dynamic

Java is designed to adapt to evolving enviroment.

Language Basics

* Data types
8 primitive types

boolean, byte, short, int, long, float, double, char.

Class types, either provided by Java, or made by programmers

String, Integer, Array, Frame, Object, Person, Animal,...

Array types

* Variables

Data Type identifier [= Expression ]:

* Flow of control

if, if-else, if-else if


for, while, do-while



Java disadvantages

* Slower than compiled language such as C

An experiment in 1999 showed that Java was 3 or 4 times slower than C or C++

Title of the article : "Comparing Java vs. C/C++ Efficiency

Issues to Interpersonal Issues" (Lutz Prechelt)

"Adequate for all but the most time-intensive programs."