Introduction To Java: Md. Samsuzzaman, Lecturer Faculty of Cse, Pstu
Introduction To Java: Md. Samsuzzaman, Lecturer Faculty of Cse, Pstu
1.
Java is a general purpose object oriented programming language. Developed by Sun Microsystems. (James Gostling) Initially called Oak but was renamed as Java in 1995. Initial motivation is to develop a platform independent language to create software to be embedded in various consumer electronics devices. Become the language of internet. (portability and security).
1.
2. 3. 4. 5. 6. 7. 8. 9.
Simple, Small and Familiar Compiled and Interpreted Object Oriented Platform Independent and portable Robust and Secure Distributed / Network Oriented Multithreaded and Interactive High Performance Dynamic
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
Similar to C/C++ in syntax But eliminates several complexities of No operator overloading No direct pointer manipulation or pointer arithmetic No multiple inheritance No malloc() and free() handles memory automatically
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
Java compiler produces an intermediate code known as byte code for a machine, known as JVM. It exists only inside the computer memory.
Java Program Java Compiler Virtual Machine
Machine code is generated by the java interpreter by acting as an intermediary between the virtual machine and real machine.
Bytecode
05/07/2008
Java Interpreter
Machine Code
7
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
Write-Once Run-Anywhere Changes in system resources will not force any change in the program. The Java Virtual Machine (JVM) hides the complexity of working on a particular platform Convert byte code into machine level representation.
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
10
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
11
Handles multiple tasks simultaneously. Java runtime system contains tools to support multiprocess synchronization and construct smoothly running interactive systems.
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
12
Java performance is slower than C Provisions are added to reduce overhead at runtime. Incorporation of multithreading enhance the overall execution speed. Just-in-Time (JIT) can compile the byte code into machine code. Can sometimes be even faster than compiled C code!
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
13
Capable of dynamically linking a new class libraries, methods and objects. Java can use efficient functions available in C/C++. Installing new version of library automatically updates all programs
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
14
Java Applets Security Portability 1. Applets: Special java program that can transmitted over the network and automatically executed by a java-compatible web browser. 2. Security: Java compatible web browser can download java applets without fear of viral infection and malicious agent.
3. Portable: Java applets can be dynamically downloaded to all the various types of platforms connected to the internet
05/07/2008 Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU 15
.
The output of java compiler is not executable code.
Once JVM exists for a platform, any java program can run on it. The execution of byte code by the JVM makes java programs portable. Java program is confined within the java execution environment and cannot access the other part of the computer.
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
16
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
17
Phase 1
Editor
Disk
Program is created in an editor and stored on disk in a file ending with .java. Compiler creates bytecodes and stores them on disk in a file ending with .class.
Phase 2
Compiler
Phase 3
Class Loader
Disk
.. . .. .
Class loader reads .class files containing bytecodes from disk and puts those bytecodes in memory.
Phase 4
Bytecode Verifier
Primary Memory Bytecode verifier confirms that all bytecodes are valid and do not violate Javas security restrictions.
.. . .. .
Primary Memory
Phase 5
Interpreter
Interpreter reads bytecodes and translates them into a language that the computer can understand, possibly storing data values as the program executes.
05/07/2008
18
1.
Development tools-part of java development kit (JDK). Classes and methods-part of Java Standard Library (JSL), also known as Application Programming Interface (API). JDK: Appletviewer ( for viewing applets) Javac (Compiler) Java (Interpreter) Javap (Java disassembler) Javah (for C header files) Javadoc ( for creating HTML description) Jdb (Java Debugger)
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
19
2. Application Package Interface (API) Contains hundreds of classes and methods grouped into several functional packages: Language Support Package Utility Packages Input/Output Packages Networking Packages AWT Package Applet Package
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
20
1. Java 1.0 2. Java 1.1 (Add new library, redefine applet handling and reconfigured many features.) 3. Java 2 (Second generation). Version no:1.2 (Internal version number of java library). Also known as J2SE [ Java 2 Platform Standard Edition]. - Add swing, the collection framework, enhanced JVM etc. 4. J2SE 1.3 5. J2SE 1.4 6. J2SE 1.5 7. J2SE 1.6
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
21
Three versions of the Java 2 Platform, targetted at different uses Java 2 Micro Edition (J2ME) Very small Java environment for smart cards, pages, phones, and set-top boxes Subset of the standard Java libraries aimed at limited size and processing power Java 2 Standard Edition (J2SE) The basic platform J2SE can be used to develop client-side standalone applications or applets. Java 2 Enterprise Edition (J2EE) For business applications, web services, mission-critical systems Transaction processing, databases, distribution, replication
05/07/2008
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
22
Chapter One of the text book. Software Used for the Course: 1. Java 2 (Version 6) 2. NetBean IDE 3. J creature - Sun.java.com
Md. Samsuzzaman ,Lecturer Faculty of CSE, PSTU Mosarratj Jahan, Dept. of CSE, DU
23