Computer Programming 2
Computer Programming 2
AUTHOR:
Hello! Please do not
reproduce my notes,
thank you! Goodluck,
future IT!
CLASS – defines a kind of object. It is a blueprint that - Data type – method that returns a value. It is
defines the variables and methods common to all required to use the return keyword in method
objects of a certain kind. body.
- void – method that does not return any value.
INHERITANCE – enables new objects to take on the
properties of existing objects. It is used to avoid METHOD NAME – an identifier and is case sensitive.
repetition of programming instructions for each Recommended to use PascalCase.
class. It makes use of the extends keyword.
PARAMETER – is used to pass and receive data from
- BASE / SUPERCLASS / PARENT CLASS / a method.
ANCESTOR CLASS – the existing class that the
ABOUT PARAMETERS:
derived class the built upon. The class whose
properties are inherited by another class. - a method may contain no parameter
- DERIVED / SUBCLASS / CHILD CLASS / - a method may contain list of parameters
DESCENDANT CLASS – defined by adding - data type of parameters depends on
instance variables and method to an existing method’s return type.
class. The class that inherits all features from the
base class and have its own additional METHOD BODY – a set of statements that performs
features. the specific task of the method.
INTERFACE – contains the headings for a number of ENCAPSULATION – process of combining data and
public methods. It can also define public names actions into a single item. To implement
constants. It uses the keyword implements. encapsulation, declare the modifier of all fields as
private.
PACKAGE – a collection of related classes and
interfaces that have been grouped together into a CONSTRUCTOR – special method that is used to
folder. It is used with the import keyword. create and initialize an object.
ACCESS MODIFIER – it determines the access level of - Static variables that are not constants should
the method from another class. be private
- These should be accessed and changed only
TYPES OF ACCESS MODIFIER: via accessor(get) and mutator (set) methods.
- Can be invoked without using any object
COMPUTER PROGRAMMING 2
AUTHOR:
Hello! Please do not
reproduce my notes,
thank you! Goodluck,
future IT!
- Invoked by using the class name instead of the class must implement, and uses the keyword
object name implements.
TYPES OF EXCEPTIONS:
- An abstract class may contain abstract - CATCH BLOCK – a segment of code that can
handle an exception that might be thrown by
methods and accessor
the try block that precedes it.
- A derived class must include actual
implementation of all inherited abstract
methods
INTERFACE – contains the headings for a number of - getMessage() – method that can be used to
public methods. It is used to specify methods that a determine Java’s message about the
exception
COMPUTER PROGRAMMING 2
AUTHOR:
Hello! Please do not
reproduce my notes,
thank you! Goodluck,
future IT!
- FINALLY BLOCK – contains statements which are - Permanent files are commonly stored in the
executed whether or not an exception is main directory or the root directory. To organize
thrown. stored files, folders or directories are used.
- Writing to a file
- Closing a file
USER-DEFINED EXCEPTIONS – created by extending
the Exception class. - Deleting a file
DELETING A PATH
TO USE READATTRIBUTES():
COMPUTER PROGRAMMING 2
AUTHOR:
Hello! Please do not
reproduce my notes,
thank you! Goodluck,
future IT!
FLUSHING – clears any bytes that have been sent to - write(byte[] b, int off, int len) – writes bytes to the
a buffer for output but have not yet been displayed output stream from the specified byte array
to a hardware device. starting at offset position off for a length of len
characters.
STANDARDOPENOPTION ARGUMENT:
- BufferedWriter – writes text to a character- - read(char[] buffer, int off, int len) – reads
output stream. character into a portion of an array from
position off for len characters.
OUTPUTSTREAMS METHODS: (void)
- readLine() – reads a line of text.
- close() – closes the output streams and releases
any system resources associated with the - skip(long n) – skips the specified number of
stream. characters.
- flush() – flushes the output stream; if any bytes SEQUENTIAL DATA FILES
are buffered, they will be written. BufferedWriter – class that writes text to an output
- write(byte[] b) – writes all bytes to the output stream, buffering the characters.
stream from the specified byte array. BUFFEREDWRITER METHODS:
TO DECLARE ENUM:
TO ASSIGN CONSTANTS:
NESTED CLASSES