1 / 35

Java and its Evolution

Java and its Evolution. Contents. Java Introduction Java Features How Java Differs from other OO languages Java and the World Wide Web Java Environment Build your first Java Program Summary and Reference. Java - An Introduction.

hea
Télécharger la présentation

Java and its Evolution

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java and its Evolution

  2. Contents • Java Introduction • Java Features • How Java Differs from other OO languages • Java and the World Wide Web • Java Environment • Build your first Java Program • Summary and Reference

  3. Java - An Introduction • Java - The new programming language developed by Sun Microsystems in 1991. • Originally called Oak by James Gosling, one of the inventors of the Java Language. • Java Authors: James , Arthur Van , and others • Java is really “C++ -- ++ “

  4. 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.

  5. Sun white paper defines Java as: • Simple and Powerful • Safe • Object Oriented • Robust • Architecture Neutral and Portable • Interpreted and High Performance • Threaded • Dynamic

  6. Java is Compiled and Interpreted Programmer Hardware and Operating System Source Code Byte Code Text Editor Compiler Interpreter .java file .class file java appletviewer netscape Notepad,emacs,vi javac

  7. Total Platform Independence JAVA COMPILER (translator) JAVA BYTE CODE (same for all platforms) JAVA INTERPRETER (one for each different system) Windows 95 Macintosh Solaris Windows NT

  8. 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.

  9. 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

  10. How Does Java Compare to C++ and Other OO Languages?

  11. Overlap of C, C++, and Java C++ C Java

  12. 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 ?

  13. Java Integrates Power of Compiled Languages and Flexibility of Interpreted Languages

  14. Java Applications • We can develop two types of Java programs: • Stand-alone applications • Web applications (applets)

  15. Applications v/s Applets • Different ways to run a Java executable code are: Application- A stand-alone program that can be invoked from command line . A program that has a “main” method. It is executed by the Java Interpreter. Applet- A program embedded in a web page , to be run when the page is browsed . A program that contains no “main” method. It is executed on a Java-enabled web browser.

  16. Java Development Kit • javac - The Java Compiler • java - The Java Interpreter • jdb- The Java Debugger • appletviewer -Tool to run the applets • javap - to print the Java bytecodes • javaprof - Java profiler • javadoc - documentation generator • javah - creates C header files

  17. Process of Building and Running Java Programs Text Editor Java Source Code javadoc HTML Files javac Java Class File javah Header Files java jdb Output

  18. Java Program Structure • A Java program consists of: • One or more classes • A class contains one or more methods • A method contains program statements • We will explore these terms in detail

  19. Java Program Structure // comments about the class public class MyProgram { } class header class body Comments can be placed almost anywhere

  20. Java Program Structure // comments about the class public class MyProgram { } // comments about the method public static void main (String[] args) { } method header method body

  21. Hello World // HelloWorld.java public class HelloWorld { } public static void main (String[] args) { } System.out.println(“Hello World!”);

  22. Hello World // HelloWorld.java • Creates a “class” called HelloWorld • Compiled to HelloWorld.class • Classes used to define objects… later public class HelloWorld { } public static void main (String[] args) { } System.out.println(“Hello World!”);

  23. Hello World // HelloWorld.java • The “main” method is where it starts to run • Ignore “public static void” and “String[] args” for now public class HelloWorld { } public static void main (String[] args) { } System.out.println(“Hello World!”);

  24. Hello World // HelloWorld.java • Contains one “statement” • The System.out.println function comes from the Java “class library” • Ends with a semicolon (all statements do) public class HelloWorld { } public static void main (String[] args) { } System.out.println(“Hello World!”);

  25. Compiling and Running • Create the file HelloWorld.java in a text editor • Compile: • javac HelloWorld.java • Run: • java HelloWorld • Output: • Hello World!

  26. Comments • Three kinds of comments: • To simplify: comments are good // a one-line comment /* a multi-line comment */ /** a javadoc comment */

  27. Reserved Words and Identifiers • Reserved words are specified by the language • All Java reserved words are in the text • Identifiers are specified by a programmer • Maybe you: e.g. HelloWorld • Maybe someone else: e.g. println

  28. Declaring Variables • Syntax: • Examples: • int count1, int count 2; • int count = 0; • String course1 = “CMPT 126”; <variable declaration> ::= <type> <declarator>, …. ; <declarator> ::= <identifier> <declarator> ::= <identifier> = <expression>

  29. Primitive Data Types in Java • Four integer types: • byte, short, int, long • Two floating point types • float, double • One of them is for characters • char • One of them is for boolean values • boolean

  30. Expressions and Assignment • An expression is a combination of one or more operators and operands • Arithmetic operators: +, -, *, /, % • Use the normal order of operations e.g. int exp = 2 * 5 +7; count = count + 1; count++; • Boolean operators: &&, ||

  31. More Assignment Operators • x += y is equivalent to x = x + y

  32. Example: String Objects • We have already seen one object type in Java: String • A String object is a list of characters e.g. “Hello world!” or “My name is Aaron” • Can be passed to print or println • Can be concatenated using the (+) operator e.g. “Hello world! ” + “My name is Aaron” “I can also append numbers, like “ + 2

  33. Object Instances • We must create a new “instance” of an object to store something • Each object type has a constructor (more later) • Create instances using the reserved world new e.g. course = new String(“CMPT 126”); • This creates a new String in memory • It stores the characters “CMPT 126” • The assignment sets course to refer to this instance

  34. References and Instances String course; course: new String(“CMPT 126”) CMPT 126 course = new String(“CMPT 126”); course: CMPT 126

  35. Summary • Java has emerged as a general purpose OO language. • It supports both stand alone and Internet Applications. • Makes the Web Interactive and medium for application delivery. • Provides an excellent set of Tools for Application Development. • Java is ubiquitous!

More Related