Professional Documents
Culture Documents
Introduction to Java
1
Basic Object-Oriented
Programming (OOP)
2
Object-Oriented Programming
Object-Oriented Programming
Focuses on objects and classes based on real world scenarios
Emphasizes state, behavior, and interaction of objects
Advantages
- Faster development
- Increased quality
- Easier maintenance
- Enhanced modifiability
- Increased software reuse 3
Classes and Objects
Class
collection of objects is called class.
can also be define as blueprint
doesn't consume any space.
Ex:
Vehicle
4
Classes and Objects (cont…)
Object
any entity that has state and behavior is known as an object
can be physical or logical
consumes space
Ex:
Car is an instance of Vehicle
5
Classes and Objects (cont…)
CLASS OBJECT
Brand Brand Lamborghini
7
What is Java?
Java
programming language that is class-based
high-level programming language
fundamentals of Java came from a programming language called C++.
8
History of Java
James Gosling
Originally developed Java at Sun Microsystems, a company now owned by
Oracle.
10
Structure of Java Program
Documentation Section
You can write a comment in this section. Comments are beneficial for the
programmer because they help them understand the code. These are
optional, but we suggest you use them because they are useful to
understand the operation of the program, so you must write comments
within the program.
11
Structure of Java Program (cont…)
Package Statement
You can create a package with any name. A package is a group of classes
that are defined by a name. That is, if you want to declare many classes
within one element, then you can declare it within a package. It is an
optional part of the program, i.e., if you do not want to declare any
package, then there will be no problem with it, and you will not get any
errors. Here, the package is a keyword that tells the compiler that package
has been created.
12
Structure of Java Program (cont…)
Import Statements
This line indicates that if you want to use a class of another package, then
you can do this by importing it directly into your program.
13
Structure of Java Program (cont…)
Interface Statement
Interfaces are like a class that includes a group of method declarations.
It's an optional section and can be used when programmers want to
implement multiple inheritances within a program.
14
Structure of Java Program (cont…)
Class Definition
A Java program may contain several class definitions. Classes are the
main and essential elements of any Java program.
15
Structure of Java Program (cont…)
16
Structure of Java Program (cont…)
17
4
Classes and Methods
18
Classes and Methods
Class
This is the basic structure of the object-
oriented programming
Can be define as blueprint or a template
Made up of attributes and behavior
19
Classes and Methods (cont…)
20
Classes and Methods (cont…)
Defining a class
21
Classes and Methods (cont…)
Method
Collection of statements that grouped
together to perform an operation
Specifies the behavior(s) of the class and
is define within the class
May or may not be bounded by a return
statement
22
Classes and Methods (cont…)
Defining a method
23
5
Syntax and Runtime Error
24
Syntax and Runtime Error
Syntax Error
A character or string incorrectly placed in a
command or instruction that causes a failure in
execution
These problem may cause unplaced command
or instruction.
-Placing “;” (semicolon) on the end of the
statement
25
Syntax and Runtime Error (cont…)
Runtime Error
A program error that occurs while program is
running, may or may not cause program to stop
Also called logic error
Some error that do not cause the program to
stop are:
-Infinite loops
-Programs with wrong outputs 26
Syntax and Runtime Error (cont…)
Runtime Error
A program error that occurs while program is
running, may or may not cause program to stop
Also called logic error
Some error that do not cause the program to
stop are:
-Infinite loops
-Programs with wrong outputs 27
6
Java Program
Statements
28
Java Program Statements
29
7
Java Comments
30
Java Comments
Comments
These are notes written to a code for documentation
purposes.
Those texts are not part of the program and does not
affect the flow of the program.
31
Java Comments (cont…)
32
Java Comments (cont…)
33
Java Comments (cont…)
C-Style Comments
C-Style comments starts with a /* and ends with a */
All the text between the two delimiters are treated as
comments
34
Java Comments (cont…)
35
Java Comments (cont…)
36