![]() You should be able to see the instance of a Tree on your cursor.ĭrag the instance into the world with your cursor and drop it onto the world. Right click on the Class Tree, select new Tree(). These are the classes available for you in this scenario. On the right hand side(above the compile button) is the Class display. If you don’t see the blue background click on Compile button (right bottom corner). You will see a screen that looks like the picture below: Open the scenario L1S3ungle in Greenfoot. Launch Greenfoot by clicking on the Greenfoot icon on your desktop. Extract the contents of L1S3_Jungle.zip into this folder. You will see in the student folder a file MyWorldApp.java, and a zip file L1S3_Jungle.zip.Ĭreate a folder GreenfootCourseScenarios. ![]() You should download and install JDK and Greenfoot before starting exercises.Īlso download the Lesson1 zip folder from Ĭreate a directory called student in your root directory.Įxtract the contents of the zip folder in this directory. We will learn in two environments, a fun java learning environment called Greenfoot and the very traditional way in which you write your code in an editor like Notepad, compile and run it using command window(in Windows) or Terminal (in Mac). You will learn to appreciate these definitions better as we do some hands on exercises. Class by itself can’t do much till an Object of that Class is created. Object is an instance of the class from which it was created.Ī class is a template or a specification for the object. They have attributes and they can do things.Ī class defines the actions and the attributes of an object. In OOP, we create objects which are like real world Objects. The things an Object can do are its methods. Despite their differences both are basically cars. These properties are the attributes of a Car. They have different values for properties like color, make, model, Horse Power, mileage etc. You could say that they are both Objects of Class Car. One is a Lamborghini, the other a Chevrolet Impala. You will also learn to appreciate the convenience of using an Object Oriented Programming Language.įor now, let us focus on understanding classes and objects. As we proceed through the course you will learn what Object Oriented Programming means. Java is an Object Oriented Programming (OOP) language. Your goal is to have a conversation as below: I recommend downloading Notepad from App store to your Mac for editing your java code files.Ĭhange the code in the greet method of class Alien to print “How are you?” instead of “Hello World!”.įind the line that calls the talk method. Instead of dir you will use ls to list files in a directory. You will use cd to navigate to the student folder just like in windows. You can find the Terminal in Application -> Utilities. If you are using a Mac, you have to use the Terminal. You would see “Hello World!” printed on the window. You can run your program by typing java MyWorldApp in the command window. We will learn how to package and distribute your program in later classes. These class files can now be run in any computer that has Java Runtime installed. You will see 2 new files listed – Alien.class and MyWorldApp.class Type the command dirand check that the file MyWorldApp.java is listed.Ĭompile the code by typing javac MyWorldApp.java ![]() Launch the command window by typing cmd in the search text box.Ĭhange the directory by typing cd C:\student in the command window. The next line Tom.greet() calls the code in the greet() method of Class Alien. (It is same as right clicking on a class in the screen editor of Greenfoot and placing it into the world.) This line creates an instance of class Alien. Pay attention to the green highlighted line in main. There is another Class MyWorldApp in this program. The yellow highlighted terms above are methods. Everything till end of line is ignored by Java. This is used when your comments will span many lines.įor a single line comment you can use //. The lines highlighted in blue are comments.Ī comment can start with /* and end with */. ![]() This prints “HelloWorld!” to the output of your system. There is only one line of actual code in this method. There are two classes in the code you see above.Ĭlass Alien has 2 methods- greet() and talk().Įxamine the code inside the method greet. Open this file using Notepad. The code looks like this: You should see a file MyworldApp.java in student folder. You would have downloaded the zip file and extracted it in the student folder. Write true if the statement is correct and false if it is.If you followed the instructions in the first part of this lesson,
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |