Intro to JavaThe PlanWhy know the lingo?Terminology to KnowMoveTester.javaMoveTest.javaSlide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Why know and follow the Java Coding Conventions?Coding ConventionsGreeterTest.javaGreeter.javaSlide 23Introduction to Java Downloading Source CodeAssignment #1CompSci 4 2.1Intro to JavaIntro toJava•Anatomy of a Class & Terminology •Running and Modifying a ProgramCompSci 4 2.2Intro to JavaThe PlanGo over MoveTest.javaSimilar to Horstmann p. 48Basic coding conventionsReview with GreeterTest.java (Horstmann)More terminology with Greeter.java (Horstmann)Homework 0 reminderHomework 1 assigned (due in 1 week)CompSci 4 2.3Intro to JavaWhy know the lingo?It’s difficult to read the textbooks if you don’t understand the wordsYour compiler error messages use specific words with specific meaningsYou need to be able to express your questions so others can understand themThe answers you receive will use the lingoCompSci 4 2.4Intro to JavaTerminology to KnowPackageClassImportKeywordPublicObjectIdentifierDeclarationDefinitionBodyStaticVoidReturnMethodMainParameterStringArrayTypeVariableLocalConstructorInitializeAssignArgumentsCommentsCalling a methodSystem.out.printlnCompSci 4 2.5Intro to JavaMoveTester.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15, 25); // print the moved rectangle System.out.println(cerealBox); }}Printsjava.awt.Rectangle[x=20, y=35, width=20, height=30]CompSci 4 2.6Intro to JavaMoveTest.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15, 25); // print the moved rectangle System.out.println(cerealBox); }}Printsjava.awt.Rectangle[x=20, y=35, width=20, height=30]abstract windowing toolkit packageRectangle classjava packageimport means to bring into the program classes or packages not in the package java.langimport is a keyword – it is a word with a special meaningCompSci 4 2.7Intro to JavaMoveTest.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15, 25); // print the moved rectangle System.out.println(cerealBox); }}Printsjava.awt.Rectangle[x=20, y=35, width=20, height=30]public means usable by everything, public is also a keywordclass means instruction and data for making objects,class is a keywordMoveTest is the name of the classA class name must match the file name.Names are also called identifiers.Identifiers and keywords are mutually exclusive.CompSci 4 2.8Intro to JavaMoveTest.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15, 25); // print the moved rectangle System.out.println(cerealBox); }}class declarationclass definition.class body{} Starts and endsclass bodyCompSci 4 2.9Intro to JavaMoveTest.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15, 25); // print the moved rectangle System.out.println(cerealBox); }}Printsjava.awt.Rectangle[x=20, y=35, width=20, height=30]Static means one per classvoid means no return valuemain is the nameof the methodCompSci 4 2.10Intro to JavaMoveTest.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15, 25); // print the moved rectangle System.out.println(cerealBox); }}Printsjava.awt.Rectangle[x=20, y=35, width=20, height=30]String is a sequence of characters[] means an arrayargs is a parameterCompSci 4 2.11Intro to JavaMoveTest.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15, 25); // print the moved rectangle System.out.println(cerealBox); }}Printsjava.awt.Rectangle[x=20, y=35, width=20, height=30]method declarationmethod definitionmethod body{} Starts and endsmethod bodyCompSci 4 2.12Intro to JavaMoveTest.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15, 25); // print the moved rectangle System.out.println(cerealBox); }}Printsjava.awt.Rectangle[x=20, y=35, width=20, height=30]Rectangle is a type (also a class)cerealBox is a variableCreates a RectangleCalls the constructor ofthe Rectangle classCompSci 4 2.13Intro to JavaMoveTest.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15, 25); // print the moved rectangle System.out.println(cerealBox); }}Printsjava.awt.Rectangle[x=20, y=35, width=20, height=30]Declaring the cerealBox variable of type RectangleInitializing the cerealBox variableCompSci 4 2.14Intro to JavaMoveTest.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15, 25); // print the moved rectangle System.out.println(cerealBox); }}Printsjava.awt.Rectangle[x=20, y=35, width=20, height=30]Assignment operatorPronounced “gets”1. Computes the right hand side2. Assigns value to left hand sideCompSci 4 2.15Intro to JavaMoveTest.javaimport java.awt.Rectangle; public class MoveTest{ public static void main(String[] args) { Rectangle cerealBox = new Rectangle(5, 10, 20, 30); // move the rectangle cerealBox.translate(15,
View Full Document