DOC PREVIEW
Duke CPS 004 - The Plan

This preview shows page 1-2-24-25 out of 25 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

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 PlanGo over MoveTest.javaSimilar to Horstmann p. 48Basic coding conventionsReview with GreeterTest.java (Horstmann)More terminology with Greeter.java (Horstmann)Homework 0 reminderHomework 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 wordsYour compiler error messages use specific words with specific meaningsYou need to be able to express your questions so others can understand themThe answers you receive will use the lingoCompSci 4 2.4Intro to JavaTerminology to KnowPackageClassImportKeywordPublicObjectIdentifierDeclarationDefinitionBodyStaticVoidReturnMethodMainParameterStringArrayTypeVariableLocalConstructorInitializeAssignArgumentsCommentsCalling a methodSystem.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

Duke CPS 004 - The Plan

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 1

Java 1

24 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Graphics

Graphics

20 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

Lecture

Lecture

16 pages

Chapter 6

Chapter 6

21 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Chapter 5

Chapter 5

22 pages

Lecture

Lecture

4 pages

Chapter 4

Chapter 4

10 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download The Plan
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The Plan and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The Plan 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?