Lec02_ObjectsTypesStyle_2per

Lec02_ObjectsTypesStyle_2per - 1 EECS EECS EECS EECS EECS...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 EECS EECS EECS EECS EECS EECS EECS EECS 285 285 285 285 285 285 285 285 EECS285 Lecture 02 Objects, Types, and Style Van der Linden Ch. 2-3 (and a little of 6) EECS EECS EECS EECS EECS EECS EECS EECS 285 285 285 285 285 285 285 285 2 Andrew M. Morgan Java Packages • Java allows classes to be grouped together into packages • Typically, packages are named with a hierarchy that matches the directory name • File names are named the same as the class they contain • Example: – A class called Truck belongs to the package Transport – The package Transport belongs to the package eecs285 – The class definition would be in a file named: • $CLASSPATH/eecs285/Transport/Truck.java – Inform Truck.java that it is in the package by including the following line at the top of the .java file: • package eecs285.Transport; 2 EECS EECS EECS EECS EECS EECS EECS EECS 285 285 285 285 285 285 285 285 3 Andrew M. Morgan Alright, alright… Hello World… • Indicates that the HelloWorld class belongs to the eecs285.test package • Everything in Java is object-oriented and the main() function must belong to a class. – The class HelloWorld is defined in a file named HelloWorld.java • Declaration of main() – public static method, returns nothing, and takes in one parameter – an array of strings called args • Prints a string to the console package eecs285.test; public class HelloWorld { public static void main(String args) { System.out.println("Hello World!"); } } Hello World! • The required hello world program: EECS EECS EECS EECS EECS EECS EECS EECS 285 285 285 285 285 285 285 285 4 Andrew M. Morgan Building and Running • http://java.sun.com/javase/downloads/index.jsp – Select the download under the heading “Java SE Development Kit (JDK)” • UNIX: – From the command line, compile your source code into byte codes: • javac HelloWorld.java – Produces a file named “HelloWorld.class” – Run the Java interpreter to execute the program • java eecs285.test.HelloWorld • Windows (Eclipse): – File->New->Java Project – File->New->Class • Specify package and class name • Check the box to automatically generate a main() if applicable – Run->Run 3 EECS EECS EECS EECS EECS EECS EECS EECS 285 285 285 285 285 285 285 285 5 Andrew M. Morgan Hello World: What’s Missing • What’s missing from our HelloWorld program? – Documentation! – True – for such a simple program, lots of comments might be overkill • Comments in Java //This is a single-line comment /* Enclose multi-line comments between slash-star * and star-slash pairs, like this. */ /** Special comments for use by javadoc, which created * documentation pages for your project using your * comments. These start with slash-star-star....
View Full Document

This note was uploaded on 01/19/2012 for the course EECS 285 taught by Professor Idk during the Fall '08 term at University of Michigan.

Page1 / 18

Lec02_ObjectsTypesStyle_2per - 1 EECS EECS EECS EECS EECS...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online