Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 3 Recap CSE 115 – Fall 2006. Java Source Code File Made up of: Package declaration Class definition.

Similar presentations


Presentation on theme: "Week 3 Recap CSE 115 – Fall 2006. Java Source Code File Made up of: Package declaration Class definition."— Presentation transcript:

1 Week 3 Recap CSE 115 – Fall 2006

2 Java Source Code File Made up of: Package declaration Class definition

3 Class Definition Made up of: Class Header Class Body Class Body is made up of: Definitions of properties Definitions of capabilities

4 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.

5 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

6 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.

7 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.

8 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.

9 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.

10 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.

11 Class Body Starts with a { Ends with a }

12 Constructor Special capability of a class that sets up the initial state of the object. Constructor definitions are made up of: Constructor Header Constructor Body Starts with { and ends with }

13 Constructor Header Public identifier () public means as it did before. The identifier here is the name of the constructor. Java imposes that the name of a constructor is the same as the name of the class. () are called parameter list

14 Creating an object The syntax to create an object is: new ConstructorName(); new is a keyword that indicates that you will create a new instance of the class whose constructor is named after the keyword.

15 Instantiation Dependency Relationship Informally called “uses a” Represented in UML diagrams as a dotted arrow In code, if ClassA “uses a” ClassB: public class ClassA { public ClassA() { new ClassB(); }

16 Relationships Between Classes You should recognize the formal name, the informal name, the UML relationship arc, and the way the relationship looks in code.


Download ppt "Week 3 Recap CSE 115 – Fall 2006. Java Source Code File Made up of: Package declaration Class definition."

Similar presentations


Ads by Google