Quick Start Java Learning to Program in Java












- Slides: 12

Quick. Start Java Learning to Program in Java Dr. Tom Way October 21, 2005 Applied Computing Technology Laboratory

The Java Programming Language l Developed in 1996 l Created by Patrick Naughton, James Gosling and Mike Sheridan (and others) at Sun Microsystems l Original called the “Green Project” l Uses Object-Oriented paradigm l Good for general purpose applications, web apps, databases, etc. Applied Computing Technology Laboratory 2

Java Advantages l Platform independence – “write once, run anywhere” l Fast prototyping of user interfaces l Excellent documentation l Great for teaching and learning l Increasing in popularity l Now used widely in industry l Automatic garbage collection Applied Computing Technology Laboratory 3

Java Disadvantages l Compile to Java byte code, not native l Runs on “virtual machine, ” so can be slower than native machine l Doesn’t have true multiple inheritance (but can get through multiple interfaces) l Some simple things are harder – keyboard input, primitive types vs. Objects Applied Computing Technology Laboratory 4

Java Specification Third edition available on Sun web site http: //java. sun. com l Explains: l l l l Grammar Lexical structure Types, values, variables Type conversions and promotions Packages, classes, interfaces, inheritance Arrays, exceptions, execution, blocks, statements, expressions, assignments, threads, locks Applied Computing Technology Laboratory 5

Java Grammar l Available on Sun web site l http: //java. sun. com/docs/books/jls/third_edition/html/syntax. html#18. 1 Example: Type: Identifier [Type. Arguments]{. Identifier [Type. Arguments]} {[]} Basic. Type. Arguments: < Type. Argument {, Type. Argument} > Type. Argument: Type ? [( extends | super ) Type] Identifier: IDENTIFIER Basic. Type: byte | short | char | int | long | float | double | boolean Applied Computing Technology Laboratory 6

Identifier: Identifier. Chars but not a Keyword or Boolean. Literal or Null. Literal Identifier. Chars: Java. Letter Identifier. Chars Java. Letter. Or. Digit Java. Letter: any Unicode character that is a Java letter Java. Letter. Or. Digit: any Unicode character that is a Java letter-ordigit Applied Computing Technology Laboratory 7

Step 1: Getting Started l Download & install JDK from: http: //java. sun. com/j 2 se/1. 5. 0/download. jsp l Double-click on file to run installer l Follow your nose l Check online installation instructions for helpful tips Applied Computing Technology Laboratory 8

Step 2: Eclipse l Download & install Eclipse from: http: //eclipse. org/downloads l Unzip to a directory (e. g. , C: eclipse) l Create desktop shortcut, if you like Right-click on eclipse. exe l Send to -> Desktop (create shortcut) l Applied Computing Technology Laboratory 9

Step 3: Write a simple program l File->New->Project l Select “Java Project” l Name project “Hello World” l Select File->New->Class l Name the class “Hello. World” (no spaces) l Check “public static void main()” box l Add one line in the main() method: System. out. println(“Hello world!”); Applied Computing Technology Laboratory 10

Step 4: Run the program l Right-click on Hello. World. java l Select Run As->Java Application l Watch console at bottom for output l Congratulations! Applied Computing Technology Laboratory 11

Learning more about Java l Visit the Quick. Start Languages web site http: //actlab. csc. villanova. edu/quickstart l View or download the Java API: http: //java. sun. com/j 2 se/1. 5. 0/docs/api/index. html l Read the Java Developers Almanac http: //javaalmanac. com/ l Google search for: java program examples Applied Computing Technology Laboratory 12