OVERVIEW OF JAVA JAVA Developed by Sun Microsystems
OVERVIEW OF JAVA
JAVA • Developed by Sun Microsystems (James Gosling) • A general-purpose object-oriented language • Based on C/C++ • Designed for easy Web/Internet applications • Platform independent SRM UNIVERSITY 2
FEATURES • Simple no pointers • automatic garbage collection • rich pre-defined class library http: //java. sun. com/j 2 se/1. 4. 2/docs/api/ • • Object oriented focus on the data (objects) and methods manipulating the data • all functions are associated with objects • almost all data types are objects (files, strings, etc. ) • potentially better code organization and reuse • SRM UNIVERSITY 3
Multithreaded • multiple concurrent threads of executions can run simultaneously Dynamic • libraries can freely add new methods and instance variables without any effect on their clients Multiple Inheritance - Interfaces Pure object oriented language SRM UNIVERSITY 4
• 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) http: //java. sun. com SRM UNIVERSITY 5
• Characteristics of both C++ • • Same syntax for expressions, statements and control flow Similar OO syntax (classes, access, constructors, methods, . . . ) Similar object model (single-rooted inheritance hierarchy, access to objects via reference only) Compiled to a byte-code (initially interpreted) Dynamic loading Garbage collection Concurrency and synchronization (threads) • Objects can force mutual exclusion of threads running inside them SRM UNIVERSITY 6
INSTALL JAVA • Can be installed on different platforms: Unix/Linux • Windows • Mac OS • SRM UNIVERSITY 7
COMPILE & RUN Hello. World. App. java public class Hello. World. App { public static void main(String[] args) { // Display "Hello World!" System. out. println("Hello World!"); } } C: jdk 7binjavac Hello. World. App. java C: jdk 7binjava Hello. World. App SRM UNIVERSITY «Java is CASE SENSITIVE! 8
COMPILING AND RUNNING Hello. World. javac Hello. World. java compile source code run java Hello. World. class bytecode 9
SET A CLASS PATH Windows 7: 1. From the desktop, right click the Computer icon. 2. Choose Properties from the context menu. 3. Click the Advanced system settings link. 4. Click Environment Variables. In the section System the PATH environment variable and select it. the PATH environment variable does not exist, click New. 5. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK. SRM UNIVERSITY Variables, find Click Edit. If 10
JAVA VIRTUAL MACHINE • Java is complied to byte-codes whose target architecture is the Java Virtual Machine (JVM) • The virtual machine is embeddable within other environments, e. g. web browser & operating sys. • Uses a byte-code verifier when reading in byte-codes. Java Source. javac Environment Java Byte-code Java VM . class 11
JAVA BYTECODE AND INTERPRETER • bytecode is an intermediate representation of the program (class). • The Java interpreter starts up a new “Virtual Machine”. • The JVM starts executing the users class by running it’s main() method. 12 Netprog 2002 Java Intro
JAVA PLATFORM EDITIONS SRM UNIVERSITY 13
SUPPORTED • Primitive data types – boolean – byte – short – int • Objects • Arrays • Virtual methods • Dynamic allocation • Packages • Exceptions • Interfaces SRM UNIVERSITY 14
- Slides: 14