Download ppt slides (6up)

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
1/26/15 Just a li.le about Java In today’s recita:on, we look at a “class” called First that contains two “methods”: 1.  A procedure main, which does not return a value. 2.  A func:on radius, which does return a value. We will see how to write this class in the IDE (Integrated Development Environment) Eclipse and how to execute the program –by execu:ng a call on method main. CS2110 Reci:a:on 01 1 Download and install Java Download and install Eclipse Course website tells you how: h.p://www.cs.cornell.edu/courses/CS2110/2014fa/
resources.html#Java JRE: Java Run:me Environment. A java program is compiled into the Java Virtual Machine Language, An “interpreter” interprets and actually runs your program. JDK: Java Development Kit. Contains, among other things, the program that compiles a Java program. Downloading and installing the JDK also installs the JRE. CS2110 Reci:a:on 01 Use to Eclipse reset perspec:ve window if it gets messed up List of projects (none yet) Will contain a Java program being edited 3 panes here, can choose which one you want CS2110 Reci:a:on 01 /** Class houses a sta:c procedure main and a sta:c procedure * for the area of a circle */ public class First { /** Print out "hello World and */ public sta+c void main(String[] pars) { System.out.println("Hello World"); System.out.println("Area of circle with radius 5 is " + radius(5)); } /** Return the area of a circle with radius r */ public sta+c double radius(double r) { return Math.PI * r * r; } CS2110 Reci:a:on 01 2 } 3 Java perspec:ve Eclipse: The IDE (Integrated Development Environment we use in this course to write, debug, run Java programs. Course website tells you how to install: h.p://www.cs.cornell.edu/courses/CS2110/2014fa/
resources.html and scroll down. CS2110 Reci:a:on 01 4 Add a project Use menu item File -­‐> New -­‐> Java project. Give it a name, First. Note: You get to say where the project files go. We suggest pujng them in the default place that Eclipse suggests. Note: Always start a new program in a new project! outline of file being edited, e.g. showing methods and fields 5 CS2110 Reci:a:on 01 6 1 1/26/15 Add class First Put declara:ons into class Circle Use menu item File -­‐> New -­‐> First. Give it a name, First. Click bu.on Finish CS2110 Reci:a:on 01 Copy the declara:ons of components from slide 2 into class Circle in the middle pane. 7 8 CS2110 Reci:a:on 01 Running the program Add a .java file by dragging to leo column Use menu item Run -­‐> Run. It executes method main. You may be asked: copy or to link to original? ALWAYS COPY. So changes don’t mess up original CS2110 Reci:a:on 01 9 CS2110 Reci:a:on 01 10 2