Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Syntax, Java Conventions, CSE 115 Conventions (Part 2) CSE 115 Spring 2006 January 30, February 1 & 3, 2006.

Similar presentations


Presentation on theme: "Java Syntax, Java Conventions, CSE 115 Conventions (Part 2) CSE 115 Spring 2006 January 30, February 1 & 3, 2006."— Presentation transcript:

1 Java Syntax, Java Conventions, CSE 115 Conventions (Part 2) CSE 115 Spring 2006 January 30, February 1 & 3, 2006

2 VII - Constructors Q: What is the job of the constructor? Identifying the constructor in code: public class SomeName { public SomeName() { Between the { } is the Java code that outlines what the functionality of the constructor is. }

3 VII – Constructors continued When we actually want to create an object, we need to activate the capability of the constructor, we do so by inserting the following line of code into our program: new NameOfConstructor();

4 VIII - Keywords Sometimes called reserved words, these words have a special meaning in Java and can only be used for that purpose within your code. Please note the listing of keywords for this semester linked off of the Resources page

5 IX - Identifiers Programmer defined names for program elements (“names”) Rules: 1)Begin with a letter or underscore 2)Followed by zero or more letters, numbers, underscores 3)No spaces or special characters allowed in identifiers 4)Keywords are not allowed to be identifiers

6 XI - Dependency Relationship between two classes 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(); }

7 XII - Packages package keyword indicates the class’ membership in a package. Packages are ways to organize code so that code with like purpose is kept together.

8 XIII - Comments Notes to help us remember/understand the code we write Two styles: // to the end of line comment /* Multi-line comment begin Multi-line comment ends with */

9 XIV - Composition Second relationship between classes Informally called “has a” Represented in UML with a diamond- headed arc In code:  Declare an instance variable  Create an instance of the component part  Assign that instance to the instance variable

10 XV - Variables Named storage

11 XVI – Instance Variables Variables that store information specific to a class – used to store all three types of properties discussed earlier. Declaring an instance variable: visibility type identifier;

12 XVII – Visibility Access control modifiers indicate who has access to something Visibilities are presented by keywords  private  public Q: What is the difference between the two types of visibilities?

13 XVIII – Type of a variable Java is strongly-typed When variables are declared, we must tell Java what type of thing the variable will hold on to

14 XIX – Identifiers for instance variables Begin with an underscore First letter of first word lower case First letter of subsequent words upper case _myFirstInstanceVariable


Download ppt "Java Syntax, Java Conventions, CSE 115 Conventions (Part 2) CSE 115 Spring 2006 January 30, February 1 & 3, 2006."

Similar presentations


Ads by Google