Week 2 Recap CSE 115 – Spring 2007 Object Oriented Program System of objects that communicate with one another to solve some problem. Objects Objects are made up of: Properties • Features that describe an object Capabilities • Actions that an object can perform Formalizing our Design UML class diagrams What is a class? Classes are the formal specification of what we want our objects to be and what we want them to be able to do. Class Boxes in UML Working with Eclipse Eclipse is an IDE that will help make writing our programs easier First we must Edit (write the program) Then Compile (Eclipse helps us with this by doing it as we type) Then Run (We select Run from a menu to run our programs) Java Files Java source code files end with a .java extension Once the code has been compiled, files with a .class extension are created It is these .class files that are “run” by the Java Virtual Machine. Java Syntax We need to learn about the syntax (grammar) rules of Java so that our programs will compile. Once our program compiles, we can run it. Question: Just because a program compiles, does that mean it will execute correctly? Java Syntax (cont) Java is case sensitive (as is Unix) Java Source Code File Made up of: Package declaration Class definition Package Declaration package identifier ; package is a keyword in Java – a word that has a special meaning identifier represents a name. Here we are identifying a package by name. Packages Way to organize our classes so that like classes are grouped together. Putting a class in a package forces you to put those classes in the same directory on the system. Identifiers Programmers can pick out identifiers if we follow these rules. Identifiers must begin with a letter or underscore Followed by zero or more letters, digits, or underscores No special characters allowed in an identifier Keywords are not allowed to be identifiers Identifiers (Style) Rules are enforced by compiler. Style enforced by community (i.e. your grade) Style for identifiers for packages is that the first letter of a package name is lower-case, all other letters are lower-case, and we do not see underscores in package names. Nested Packages You can put a package inside of another package. This is indicated by using the dot (period) in between package names. On the system, nested packages are directories inside other directories. If you are using something outside of your current package, you must give the fully-qualified package name. Class Definition Made up of: Class Header Class Body Class Body is made up of: Definitions of properties Definitions of capabilities Class Header public class identifier public is a keyword that is an access control modifier. It tells who has access to something. If public, everyone has access. class is another keyword that indicates we are about to start the definition of a class. The identifier here represents the name of the class. Names of Classes Must follow rules of identifiers. Style: First letter upper-case, rest lower-case. If more than one word, capitalize each new word. No underscores in class names. Whatever you name the class is whatever you will name the file the class is defined in. Class Body Starts with a { Ends with a }