[go: up one dir, main page]

0% found this document useful (0 votes)
3 views19 pages

Slot 1 Review

The document provides an overview of Object-Oriented Programming (OOP) concepts, including class structures, variables, methods, and access modifiers. It explains the components of objects, such as state and behavior, and introduces data types and method overloading. Additionally, it discusses the organization of classes into packages and the significance of access modifiers for classes and class members.

Uploaded by

datpqhe180117
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views19 pages

Slot 1 Review

The document provides an overview of Object-Oriented Programming (OOP) concepts, including class structures, variables, methods, and access modifiers. It explains the components of objects, such as state and behavior, and introduces data types and method overloading. Additionally, it discusses the organization of classes into packages and the significance of access modifiers for classes and class members.

Uploaded by

datpqhe180117
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

SLOT 1 REVIEW

CONTENT

• Class & Class Components


• Variables & Methods
• OOP Concepts: Abstraction, Encapsulation, Inheritance, Polymorphism
• Collections
• Regular expressions
• Exception handling
• Basic I/O

2
OBJECTS: STATE & BEHAVIOR

• OOP is a way to model real world objects, as attributes


instance
variables
software objects, which contain both data and
code.
Learn more
Computer
• Real world objects have two major components:
Size of RAM
o State (characteristics about the item, that can Operating system
describe it) Size of hard drive
Size of monitor
o and Behavior (actions that can be performed by
the object, or upon the object) Boot up
Shut down
Beep some sound
methods Display something

behaviours
3
Class basics
-
Person
class

4
BASIC CLASS STRUCTURE

public class Person { [access modifier] class ClassName {


private int age; // instance variable(s) 1
public void setAge(int newAge){ // mutator/setter
if(newAge > 0 && newAge <= 120)
age = newAge;
}
methods
public int getAge(){ // accessor/getter
return age; 2
}
}
// other methods
}

5
• Inside class
• Outside of any methods

• Declaration Syntax:
private datatype varName;

Instance variable Method 6


VARIABLES

• A keyword is any one of a number of reserved words, that have a predefined


meaning in the Java language.
• Variables are a way to store information in computers – named memory locations
• An expression is a coding construct, that evaluates to a single value.

7
DATA TYPES

• Primitive data types Real number


Whole number
(floating point or decimal)
• Reference data types
byte
short float
int double
long

Single character Boolean value

char boolean

8
WRAPPER CLASSES

• A wrapper class provides simple operations, as well as some basic information


about the primitive data type, which cannot be stored on the primitive itself.
Primitive Wrapper Class
byte Byte
short Short
char Character
int Integer
long Long
float Float
double Double
boolean Boolean
9
METHOD

• A method declares executable code that can be invoked, passing a fixed number
of values as arguments.
• A method is a way of reducing code duplication

10
[modifier] returnType methodName([para list]){
// method body goes here
}

private int age;

Mutator/Setter Accessor/Getter

Instance variable Method 11


METHOD OVERLOADING

• Same class, same method name, different set of parameters

12
CLASSES: BASIC CLASS STRUCTURE

Class header {

o Instance variables (who uses these variables?) – the class itself (private)

– outsiders (public)
o Constructors (who uses these constructors?)

o Accessors (who uses these accessors?)


– outsiders (public)

– outsiders (public)
o Mutators (who uses these mutators?)

– depends – can be used


o Other methods (who uses these other methods?)
internally or externally (i.e.
} can be private or public)
CLASS AS A BLUEPRINT

Class

Instance members Static members

Fields Fields
Methods Methods

14
CLASS AS A BLUEPRINT

• The class describes the data (fields), and the behavior (methods), that are relevant to
the real-world object we want to describe. These are called class members.
• A class member can be a field, or a method, or some other type of dependent element.
• If a field is static, there is only one copy in memory, and this value is associated with
the class, or template, itself.
• If a field is not static, it's called an instance field, and each object may have a different
value stored for this field.
• A static method can't be dependent on any one object's state, so it can't reference any
instance members.
Sample
o In other words, any method that operates on instance fields, needs to be non-static. code

15
PACKAGE

• Classes can be organized into logical groupings, which are called packages.
• You declare a package name in the class using the package statement.
• If you don't declare a package, the class implicitly belongs to the default package.

16
ACCESS MODIFIERS: for CLASS

• A class is said to be a top-level class, if it is defined in the source code file, and not
enclosed in the code block of another class, type, or method.
• A top-level class has only two valid access modifier options: public, or none.

Access Description
keyword

public public means any other class in any package can access this class.
When the modifier is omitted, this has special meaning, called
package access, meaning the class is accessible only to classes in the
same package.

17
ACCESS MODIFIERS: for CLASS MEMBERS

Access
keyword Description
public public means any other class in any package can access this class.
protected allows classes in the same package, and any subclasses in
protected other packages, to have access to the member.
When the modifier is omitted, this has special meaning, called
package access, meaning the member is accessible only to classes in
the same package
private private means that no other class can access this member

Sample code
18
19

You might also like