Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Review CIS 304 Intermediate Java Programming for Business.

Similar presentations


Presentation on theme: "Java Review CIS 304 Intermediate Java Programming for Business."— Presentation transcript:

1 Java Review CIS 304 Intermediate Java Programming for Business

2 Naming Variables and Classes 4 All use letters, numbers and underscores –we'll just use letters and numbers 4 Variables –starts with lower case letter –all words after first are capitalized –all words are "run together" (e.g., myBankAcct)

3 What is a Variable? 4 named location in memory 4 data type -- points at location in memory where value is stored 4 object -- points at location in memory which references storage location where all the data contents of object are stored –where are instance variables stored? –where are object's methods stored? –where are class variables stored?

4 Objects and Primitive Data Types 4 What they are –8 Primitive data types –Declaring them –Using them 4 Objects –Declaring them –Constructing them (from a class definition) –Using them

5 Casting 4 Java is "strongly typed" 4 conversion of types during mathematical operations involving mixed types 4 int can be cast to double automatically with assignment statement 4 primitive data types can be cast –ex: int a = (int) 48.7; casts a double to an int –try this in scrapbook 4 objects can be cast down the hierarchy –ex: (Person) myDictionary.get(lookUpKey);

6 Operator Precedence Listed in order of decreasing precedence !, unary +, unary - *, /, % +, - =, > ==, != && || =

7 Operator Precedence (more complete) 4 Listed in order of decreasing precedence (), [ ],. ++, -- !, unary +, unary -, !, (type) right to left *, /, % +, - =, >, instance of ==, != && || =, +=, -=, *=, /=, %= right to left

8 Classes 4 Class is a template –Class is used to construct objects –Class includes instance variables (which are maintained separately for each object) instance methods class variables, called static variables class methods, called static methods

9 this 4 private int myVar; 4 public void methodA(int myVar) 4 { this.myVar = myVar; 4 … 4 }

10 Classes You Should Know 4 String 4 NumberFormat 4 DecimalFormat 4 JOptionPane 4 Wrapper classes for the primitive data types

11 Dot Notation 4 How this is used with data types 4 object.method() 4 class.method() 4 object.instanceVariable 4 class.instanceVariable

12 Visibility 4 Concept: from where can you see/access classes, methods and variables 4 Options public private protected package

13 Scope of Variables 4 Concept: where is a variable available for use 4 Variable is only available within the braces within which it is defined 4 Guidelines –Keep variables as local as possible –Calculate values in preference to storing them –Within reason, use as few variables as possible 4 If duplicate names are used, inner name hides the outer name –easy source of errors –Ex: if varName is both an instance variable and a formal parameter, need to distinguish this.varName from varName


Download ppt "Java Review CIS 304 Intermediate Java Programming for Business."

Similar presentations


Ads by Google