Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way...

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

Transcript of Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way...

Page 1: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

Applied Computing Technology Laboratory

QuickStart Java

Learning to Program in JavaDr. Tom WayOctober 21, 2005

Page 2: 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 1996Created by Patrick Naughton, James

Gosling and Mike Sheridan (and others) at Sun Microsystems

Original called the “Green Project”Uses Object-Oriented paradigmGood for general purpose applications,

web apps, databases, etc.

Page 3: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

Applied Computing Technology Laboratory 3

Java Advantages

Platform independence – “write once, run anywhere”

Fast prototyping of user interfacesExcellent documentationGreat for teaching and learningIncreasing in popularityNow used widely in industryAutomatic garbage collection

Page 4: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

Applied Computing Technology Laboratory 4

Java Disadvantages

Compile to Java byte code, not nativeRuns on “virtual machine,” so can be

slower than native machineDoesn’t have true multiple inheritance

(but can get through multiple interfaces)Some simple things are harder –

keyboard input, primitive types vs. Objects

Page 5: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

Applied Computing Technology Laboratory 5

Java Specification

Third edition available on Sun web sitehttp://java.sun.com

Explains: Grammar Lexical structure Types, values, variables Type conversions and promotions Packages, classes, interfaces, inheritance Arrays, exceptions, execution, blocks, statements,

expressions, assignments, threads, locks

Page 6: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

Applied Computing Technology Laboratory 6

Java Grammar

Available on Sun web sitehttp://java.sun.com/docs/books/jls/third_edition/html/syntax.html#18.1

Example:Type:

Identifier [TypeArguments]{ . Identifier [TypeArguments]} {[]}BasicType

TypeArguments:< TypeArgument {, TypeArgument} >

TypeArgument:Type ? [( extends | super ) Type]

Identifier:IDENTIFIER

BasicType:byte | short | char | int | long | float | double | boolean

Page 7: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

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

Page 8: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

Applied Computing Technology Laboratory 8

Step 1: Getting Started

Download & install JDK from:http://java.sun.com/j2se/1.5.0/download.jsp

Double-click on file to run installerFollow your noseCheck online installation instructions for

helpful tips

Page 9: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

Applied Computing Technology Laboratory 9

Step 2: Eclipse

Download & install Eclipse from:http://eclipse.org/downloads

Unzip to a directory (e.g., C:\eclipse)Create desktop shortcut, if you like

Right-click on eclipse.exeSend to -> Desktop (create shortcut)

Page 10: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

Applied Computing Technology Laboratory 10

Step 3: Write a simple program

File->New->ProjectSelect “Java Project”Name project “Hello World”Select File->New->ClassName the class “HelloWorld” (no

spaces)Check “public static void main()” boxAdd one line in the main() method:

System.out.println(“Hello world!”);

Page 11: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

Applied Computing Technology Laboratory 11

Step 4: Run the program

Right-click on HelloWorld.javaSelect Run As->Java ApplicationWatch console at bottom for outputCongratulations!

Page 12: Applied Computing Technology Laboratory QuickStart Java Learning to Program in Java Dr. Tom Way October 21, 2005.

Applied Computing Technology Laboratory 12

Learning more about Java

Visit the QuickStart Languages web sitehttp://actlab.csc.villanova.edu/quickstart

View or download the Java API:http://java.sun.com/j2se/1.5.0/docs/api/index.html

Read the Java Developers Almanachttp://javaalmanac.com/

Google search for: java program examples