CSE 452: Programming Languages Java and its Evolution
Contents Java Introduction Java Features How Java Differs from other OO languages Build your first Java Program
Java - An Introduction Java - The new programming language developed by Sun Microsystems in 1 991. Originally called Oak by James Gosling, one of the inventors of the Java Language. Java -The name that survived a patent search Java Authors: Gosling, Arthur Van , and others Java is really “C++ -- ++ “
Java Introduction Originally created for consumer electronics (TV, VCR, Freeze, Washing Machine, Mobile Phone). Java - CPU Independent language Internet and Web was just emerging, so Sun turned it into a language of Internet Programming. It allows you to publish a webpage with Java code in it.
Java Milestones Year Development 1990 Sun decided to developed special software that could be used for electronic devices. A project called Green Project created and headed by James Gosling. 1991 Explored possibility of using C++, with some updates announced a new language named “Oak” 1992 The team demonstrated the application of their new language to control a list of home appliances using a hand held device. 1993 The World Wide Web appeared on the Internet and transformed the text-based interface to a graphical rich environment. The team developed Web applets (time programs) that could run on all types of computers connected to the Internet.
Java Milestones Year Development 1994 The team developed a new Web browsed called “Hot Java” to locate and run Applets. HotJava gained instance success. 1995 Oak was renamed to Java, as it did not survive “legal” registration. Many companies such as Netscape and Microsoft announced their support for Java 1996 Java established itself it self as both 1. “the language for Internet programming” 2. a general purpose OO language. 1997- A class libraries, Community effort and standardization, Enterprise Java, Clustering, etc..
Sun white paper defines Java as: Simple and Powerful Safe Object Oriented Robust Architecture Neutral and Portable Interpreted and High Performance Threaded Dynamic
Java Attributes(characterstics ) Familiar, Simple, Small Compiled and Interpreted Platform-Independent and Portable Object-Oriented Robust and Secure Distributed Multithreaded and Interactive High Performance Dynamic and Extensible
Java is Compiled and Interpreted Text Editor Compiler Interpreter Programmer Source Code .java file Byte Code . class file Hardware and Operating System Notepad, emacs,vi javac java appletviewer netscape
Compiled Languages Text Editor Compiler linker Programmer Source Code .c file Object Code . o file Notepad, emacs,vi gcc Executable Code a.out file
Total Platform Independence JAVA COMPILER JAVA BYTE CODE JAVA INTERPRETER Windows 95 Macintosh Solaris Windows NT (translator) (same for all platforms) (one for each different system)
Architecture Neutral & Portable Java Compiler - Java source code (file with extension . java ) to bytecode ( file with extension .class ) Bytecode - an intermediate form, closer to machine representation A interpreter (virtual machine) on any target platform interprets the bytecode.
Architecture Neutral & Portable Porting the java system to any new platform involves writing an interpreter . The interpreter will figure out what the equivalent machine dependent code to run
How Does Java Compares to C++ and Other OO Languages
Overlap of C, C++, and Java C C++ Java
Java better than C++ ? No Typedefs, Defines, or Preprocessor No Global Variables No Goto statements No Pointers No Unsafe Structures No Multiple Inheritance No Operator Overloading No Automatic Coercions No Fragile Data Types ?
Object Oriented Languages -A Comparison
Hello Internet // hello.java: Hello Internet program class HelloInternet { public static void main(String args[]) { System.out.println(“Hello Internet”); } }
Program Processing Compilation # javac hello.java results in HelloInternet.class Execution # java HelloInternet Hello Internet #
Java Java includes different version starting from java1.0. Version were implemented using java development kit(JDK1.1)and onwords. JDK war renamed as SDK(S/W DEVELOPMENT KIT) SDK was released in following three forms: J2ME(java 2 micro Edition) for consumer electronic product. J2SE(Java 2 Standard edition)SDK commonly used J2EE(Java 2 Enterprice Edition) for Enterprice development
Components of Java Std. Edition(JSE 7.0) Java programming language Java APIs Java Virtual Machine Java class file formats The tool required to build,compile,and debug.
Java is Compiled and Interpreted(Execution ) Java Compiler JRE Source Code .java file Byte Code . class file EXECUTION Notepad, emacs,vi javac OUTPUT AFTER
Java program structure
Architecture of java virtual m/c Stack Garbage collection Heap Method Area Registers Runtime Constant Pool Garbage collector Adaptive Optimizer Execution Engine to Execute JVM Instruction set (A java virtualchip)
1.Heap is a region of free memory use for dynamic allocation. 2.It is reclaimed by garbage collector. 3.Stack is used to store the state of method invocation, partial result(data, return values for methods). 4.Method area used to store run time constant ,method data,& byte code of method & constructors. 5.Registers are same as registers of computer system. 6.PC indicate the address of JVM current instructions . 7.Run Time constant pool is similar to symbol table. 8. The execution engine has instruction set of JVM. Architecture of java virtual m/c
Setting up the path for windows: Assuming you have installed Java in c:\Program Files\java\jdk directory: Right-click on 'My Computer' and select 'Properties'. Click on the 'Environment variables' button under the 'Advanced' tab. Now, alter the 'Path' variable so that it also contains the path to the Java executable. Example, if the path is currently set to 'C:\WINDOWS\SYSTEM32', then change your path to read 'C:\WINDOWS\SYSTEM32;c:\Program Files\java\jdk\bin'.
Popular Java Editors: Notepad: On Windows machine you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad. Netbeans: is a Java IDE that is open-source and free which can be downloaded from http://www.netbeans.org/index.html . Eclipse: is also a Java IDE developed by the eclipse open-source community and can be downloaded from http://www.eclipse.org/ .
Constants Value cannot change during program execution Syntax: final dataType constantIdentifier = assignedValue; Note: assigning a value when the constant is declared is optional. But a value must be assigned before the constant is used. See Example 2.4 Constants.java
Modifying Your First Java Program Displaying a Single Line of Textwith Multiple Statements public class Welcome2 { // main method begins execution of Java application public static void main( String[] args ) { System.out.print("Welcome to "); System.out.println("Java Programming!”); } // end method main } // end class Welcome2 Welcome to Java Programming!
Displaying Multiple Lines of Text with a Single Statementpublic class Welcome3 { // main method begins execution of Java application public static void main( String[] args ) { System.out.println("Welcome\nto\nJava\nProgramming!"); } // end method main } // end class Welcome3 Welcome to Java Programming!