Presentation is loading. Please wait.

Presentation is loading. Please wait.

Agenda For Feb 11 1. PowerPoint Presentation (Introduction to Java Methods) 2.Finish Unit 2 exercises on page 13 (due by the end of the class today). 4.

Similar presentations


Presentation on theme: "Agenda For Feb 11 1. PowerPoint Presentation (Introduction to Java Methods) 2.Finish Unit 2 exercises on page 13 (due by the end of the class today). 4."— Presentation transcript:

1 Agenda For Feb 11 1. PowerPoint Presentation (Introduction to Java Methods) 2.Finish Unit 2 exercises on page 13 (due by the end of the class today). 4. If you finish all the above read Unit 3 carefully and try Section 3.1 Mastery Questions 1, 2, & 3 (page 18) Section 3.2 Mastery Question (page 19) Unit 3 Exercises 1-3 (page 20) 3. Assignment 2 (Also to be handed in by the end of Friday).

2 Java Methods Methods contain a group of instructions that together perform a single task. For example if I want to perform the task of “making a pizza”, I would have to do the following: 1. Make the dough 2. Make the pizza sauce 3. Put sauce on the pizza 4. Put toppings on the pizza 5. Cook the pizza

3 Java Methods So when we say “make a pizza” we mean do all those instructions. Lucky for us we don’t talk using such detail because conversations would take for ever! If it takes one instruction to draw a single line how many instructions does it take to draw one of these polygons? 100 of them?

4 Java Methods A Different approach to this problem is to create a method that draws one polygon. We can then use that method to draw as many polygons as we want. This will cut down the number of instructions we’d have to write.

5 Java Methods General structure of a Java method: public void method_name () { // instruction 1 // instruction 2 // instruction 3 // … }

6 Java Methods Our method for drawing a polygon would look like this. public void drawPolygon () { /* instruction for drawing line 1 instruction for drawing line 2 instruction for drawing line 3 … */ }

7 Java Methods Methods contain a group of related instructions for the computer. For the time being we will be using methods that already exist in Java. Later in the course we will be creating our own methods from scratch. Some example of already defined Java methods are: drawString(“Anything I want goes here”, x, y); drawRect(width, height, x, y); setColor(Color.blue);

8 The import Statement Many useful Java Applet methods and variables are located in pre-made packages. If a programmer wants to use one of these methods or variables he or she must first import the package that it belongs to. Otherwise the compiler will not know where that special word came from. Import statements are used to import these useful packages. Examples of some Java special words we will be using are: AppletJava Applet Template (so we can create Applets) GraphicsJava Applet Variable (lets us draw to the screen) paintJava Applet method initJava Applet method ColorVariable

9 Java Download Websites Java Developers Kit (Compiler) http://java.sun.com/j2se/1.4.2/download.html JCreator: A Java Text Editor (For Windows) Be sure to select JCreator LE version http://www.jcreator.com/Download.htm Instructions on installing JDK and JCreator http://www.cs.nyu.edu/courses/fall03/V22.0101-002/instruc.html

10 JDK Java Development Kit The JDK is a free compiler for Java offered by Sun Microsystems. Project Builder is the visual interface for the compiler. In other words Project builder is a program that allows us to use the JDK in an easy (user-friendly) fashion. Project Builder provides us with, windows, buttons, command icons, text-editor etc. Otherwise we would have to use the command line to compile our Java source code. The command to compile Java source files using just the JDK (with no Project Builder) would be: javac mySourceFile.java appletviewer MyHtmlFile.html Then to run your Applet you would type


Download ppt "Agenda For Feb 11 1. PowerPoint Presentation (Introduction to Java Methods) 2.Finish Unit 2 exercises on page 13 (due by the end of the class today). 4."

Similar presentations


Ads by Google