* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download JavaIntro
Survey
Document related concepts
Library (computing) wikipedia , lookup
Resource management (computing) wikipedia , lookup
Falcon (programming language) wikipedia , lookup
Java syntax wikipedia , lookup
Design Patterns wikipedia , lookup
Name mangling wikipedia , lookup
Comment (computer programming) wikipedia , lookup
Class (computer programming) wikipedia , lookup
Scala (programming language) wikipedia , lookup
C Sharp syntax wikipedia , lookup
Object-oriented programming wikipedia , lookup
C Sharp (programming language) wikipedia , lookup
Transcript
Java Coding Introduction Scott McElfresh SAMS 2004 Software Creation Cycle Edit Compile Run Test Debug Software Creation Cycle Edit Compile java programname sh run.sh Test javac programname.java sh compile.sh Run word processor, text editor, Project Builder make sure everything works as desired Debug Objects, Classes, and Behavior In Java programming, items of interest are called objects Objects that share common behavior are grouped into classes. Once a class is defined in Java, objects of that class can be created. These are called instances. Java has some classes pre-defined for us. In this course, we will also use classes created by other programmers. Messages Requesting that an object do something (execute one of its behaviors) is called a sending a message, or calling a method. To send a message, we must specify the object and the desired behavior. EG: bob.goToStore(); jane.goToStore(butter); // butter is a “parameter” bill.howOldAreYou() Variables Variables in Java refer to specific objects. Java needs a way to refer to the object, so requires an identifier. Identifiers can have letters and numbers, and must start with a letter. Conditional code Some actions are only desirable under certain conditions. if (out of butter) mary.goToStore(butter) If statements allow us to check the state of the world and make a decision about what to do. if (mary.outOfButter()) mary.goToStore(butter); else mary.goToFriendsHouse(); Comments and Internal Documentation Comments are code for HUMANS to read, not the computer. /* …. */ indicates comments between. // indicates comments on the rest of the line Project builder typically makes these green. Items on screen in this project 1. 2. 3. 4. For each item on your screen, you need to do 3 or 4 things: Choose a name for the item. Declare this to Java. Create the item and fill in details (eg. location size) Add it to your display and tell Java how this item relates to other items on screen. Tell Java what to do when this item is in focus and phone keys are pressed.