Lecture 1
Lecture 1
Muhammad Bilal
History
• Java is simple
• Java is object-oriented
• Java is distributed
• Java is interpreted
• Java is robust
• Java is secure
• Java is portable
• Java’s performance
• Java is multithreaded
• Java has garbage
Collector
Java Features (1)
Simple
• fixes some clumsy features of C++
• no pointers
• automatic garbage collection
• rich pre-defined class library
Object oriented
Interpreted
• java compiler generate byte-codes, not native machine
code
• the compiled byte-codes are platform-independent
• java bytecodes are translated on the fly to machine
readable instructions in runtime (Java Virtual Machine)
Portable
• same application runs on all platforms
• the sizes of the primitive data types are always the same
Java Features (3)
Reliable
• extensive compile-time and runtime error checking
• no pointers. Memory corruptions or unauthorized
memory accesses are impossible
• automatic garbage collection tracks objects usage over
time
Secure
• usage in networked environments requires more security
• memory allocation model is a major defense
• access restrictions are forced (private, public)
Java Features (4)
Multithreaded
• multiple concurrent threads of executions can
run simultaneously
• utilizes a sophisticated set of synchronization primitives (based
on monitors and condition variables paradigm) to achieve this
Java Disadvantages
• title of the article: “Comparing Java vs. C/C++ Efficiency Issues to Interpersonal
Issues” (Lutz Prechelt)
• Java programs can be run from a Web browser. Such programs are
called applets. Applets employ a modern graphical interface with
buttons, text fields, text areas, radio buttons, and so on, to interact
with users on the Web and process their requests.
• You can use a Java development tool (e.g., NetBeans, Eclipse, and
Text Pad)—software that provides an integrated development
environment (IDE) for developing Java programs quickly.
Compile and Run
Creating..Compiling .. Executing
Create/Modify Source
Code
Bytecode
Java Java Java
Interpreter Interpreter Interpreter
Run Byteode ...
i.e. java Welcome on Windows on Linux on Sun
Solaris
Result
If runtime errors or
incorrect result
Java is case sensitive
Anatomy of a Java Program
Comments:
In Java, comments are preceded by two slashes (//) in a line, or enclosed between
/* and */ in one or multiple lines. When the compiler sees //, it ignores all text after
// in the same line. When it sees /*, it scans for the next */ and ignores any text
between /* and */.
Package :
The second line in the program (package javaapplication1;) specifies a package
name, javaapplication1, for the class javaapplication1. It compiles the source code
in javaapplication1.java, generates javaapplication1.class, and stores
javaapplication1.class in the javaapplication1 folder.
Anatomy of a Java Program
Reserved words:
Reserved words or keywords are words that have a specific meaning to the
compiler and cannot be used for other purposes in the program. For example, when
the compiler sees the word class, it understands that the word after class is the
name for the class. Other reserved words are public, static, and void etc.
Modifiers:
Java uses certain reserved words called modifiers that specify the properties of the
data, methods, and classes and how they can be used. Examples of modifiers are
public and static. Other modifiers are private, final, abstract, and protected. A
public datum, method, or class can be accessed by other programs through reserve
words
CE&ME, NUST
Anatomy of a Java Program
Statements:
Blocks:
CE&ME, NUST