![]() A constructor is executed EACH time a class is instantiated.ġ9 Java Programming with BlueJ Assignment Statements ![]() Note class name is the same as the constructor A constructor is a method that has the same name as the class and provides the initial values for an object. Instance variables Method acting on the instance variableġ8 Java Programming with BlueJ Constructors Methods are just sequences of computer instructions. Methods – the actions taken on the data items. The computer instructions in the methods act on these data items. A single line comment begins with // (no spaces) Multi-line comments for more detailed explanations start with /* and end with */ A multi-line commentġ7 Programming in Java with BlueJ Class definitionĪ class definition contains: Instance variables – the data items for the class. All other parts are required.Ĭomments are included in a program to provide information to the reader about how the source code performs or was created. public void moveVertical(int distance) 1) Access modifier 2) Return type 3) Name 4) Parameter list NOTE: If the parameter list is empty the parentheses MUST remain. Some methods require parameters, these parameters have a type int – numeric values without decimals -5, 100, float – numeric values with decimals -0.456, 9.65, 100.1 String – a combination of alphanumeric symbols grouped with quotation marks “ “ “red”, “101 College Parkway”, “123”ġ5 Java Programming with BlueJ Method Signatures All methods included in the class are here.ġ4 Java Programming with BlueJ Data Types The source code for the methods is shown here in the class definition. ![]() Right-click the class, click Open Editor.ġ3 Java Programming with BlueJ Viewing the Source Code The source code for a class can be viewed by opening the editor. Method signatureġ2 Java Programming with BlueJ Viewing the Source Code Note that the method signature indicates the type of data to be entered. When a method requires a parameter you will get a second window to enter that parameter. For example the moveVertical method requires a distance and changeColor requires a color Parameters to methodsġ1 Java Programming with BlueJ Method Signatures Some methods require a parameter be passed to it. makeVisible( ) from the menu creates the blue ball in another windowġ0 Java Programming with BlueJ Parameters You should see a blue ball appear in a separate window. To invoke the methods of each class Right-click the object on the object bench Click the method to invoke from the menu, try makeVisible( ) To create an instance of the Circle class in the shapes project Right click the Circle class Click new Circle( ) Name the instance and click OK Note the naming conventions of lowercase for objects and uppercase for classes Class Object on the Object BenchĨ Java Programming with BlueJ Invoking Methods If each class has /’s under them RIGHT click on each class Select Compileħ Java Programming with BlueJ Creating Instances of Classes The shapes project initially looks like this: The shapes projectĦ Opening setup You may need to COMPILE the given files We will examine the features of BlueJ by working with the shapes project. Will need to do this: For THIS presentation And whenever you SAVE and return to a project Directions Open BlueJ Project -> Open Project -> C:\BlueJ\examples\shapes View the source code Give examples of different data types Identify the 4 parts of a method signature Identify comments Identify accessor and mutator methods Use the printing methods Use selection statements Identify local variables Lupoliīy the end of this presentation you should be able to: Open a BlueJ project Create an instance of a class Invoke methods of a class Toggle between the project window and the output window Identify parameters to a method ![]() Presentation on theme: "Java Programming with BlueJ"- Presentation transcript:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |