Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005
Applied Computing Technology Laboratory 2 The Java Programming Language Developed in 1996 Created by Patrick Naughton, James Gosling and Mike Sheridan (and others) at Sun Microsystems Original called the “Green Project” Uses Object-Oriented paradigm Good for general purpose applications, web apps, databases, etc.
Applied Computing Technology Laboratory 3 Java Advantages Platform independence – “write once, run anywhere” Fast prototyping of user interfaces Excellent documentation Great for teaching and learning Increasing in popularity Now used widely in industry Automatic garbage collection
Applied Computing Technology Laboratory 4 Java Disadvantages Compile to Java byte code, not native Runs on “virtual machine,” so can be slower than native machine Doesn’t have true multiple inheritance (but can get through multiple interfaces) Some simple things are harder – keyboard input, primitive types vs. Objects
Applied Computing Technology Laboratory 5 Java Specification Third edition available on Sun web site Explains: 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 6 Java Grammar Available on Sun web site Example: Type: Identifier [TypeArguments]{. Identifier [TypeArguments]} {[]} BasicType TypeArguments: TypeArgument: Type ? [( extends | super ) Type] Identifier: IDENTIFIER BasicType: byte | short | char | int | long | float | double | boolean
Applied Computing Technology Laboratory 7 Identifier Identifier: IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral IdentifierChars: JavaLetter IdentifierChars JavaLetterOrDigit JavaLetter: any Unicode character that is a Java letter JavaLetterOrDigit: any Unicode character that is a Java letter-or- digit
Applied Computing Technology Laboratory 8 Step 1: Getting Started Download & install JDK from: Double-click on file to run installer Follow your nose Check online installation instructions for helpful tips
Applied Computing Technology Laboratory 9 Step 2: Eclipse Download & install Eclipse from: Unzip to a directory (e.g., C:\eclipse) Create desktop shortcut, if you like Right-click on eclipse.exe Send to -> Desktop (create shortcut)
Applied Computing Technology Laboratory 10 Step 3: Write a simple program File->New->Project Select “Java Project” Name project “Hello World” Select File->New->Class Name the class “HelloWorld” (no spaces) Check “public static void main()” box Add one line in the main() method: System.out.println(“Hello world!”);
Applied Computing Technology Laboratory 11 Step 4: Run the program Right-click on HelloWorld.java Select Run As->Java Application Watch console at bottom for output Congratulations!
Applied Computing Technology Laboratory 12 Learning more about Java Visit the QuickStart Languages web site View or download the Java API: Read the Java Developers Almanac Google search for: java program examples