Java Syntax, Java Conventions, CSE 115 Conventions (Part 2) - PowerPoint PPT Presentation

About This Presentation
Title:

Java Syntax, Java Conventions, CSE 115 Conventions (Part 2)

Description:

Begin with a letter or underscore. Followed by zero or more letters, numbers, underscores ... Two styles: // to the end of line comment /* Multi-line comment begin ... – PowerPoint PPT presentation

Number of Views:105
Avg rating:3.0/5.0
Slides: 15
Provided by: cseBu
Learn more at: https://cse.buffalo.edu
Category:

less

Transcript and Presenter's Notes

Title: Java Syntax, Java Conventions, CSE 115 Conventions (Part 2)


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
  • Begin with a letter or underscore
  • Followed by zero or more letters, numbers,
    underscores
  • No spaces or special characters allowed in
    identifiers
  • 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
Write a Comment
User Comments (0)
About PowerShow.com