Lesson 1. Object-Oriented Programming Concepts

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 50

gClass codes: 464iphp

IT ELEC 2

Object-Oriented
Programming
INSTRUCTOR: KRYSTEL JANE L AJIAS
ASSOCIATE IN COMPUTER TECHNOLOGY
BS INFORMATION TECHNOLOGY
DIPLOMA IN PROFESSIONAL EDUCATION
MA EDUCATION (CAR)
MS INFORMATION TECHNOLOGY (ON-GOING)
Course Description
This three (3) units course introduces the concepts of object-
oriented programming to students using Java with a
background in the procedural paradigm.
The course begins with a review of basic structures and data
types in Java. Moreover, the course also introduces students the
object-oriented programming paradigm, focusing on the definition
and use of classes along with the fundamentals of object-
oriented design.
Course General Objectives:

 Write Java programs in solving simple computing problems


using the procedural and functional programming
 Explain and describe the fundamental concepts and features of
object-oriented design and programming
 Design and implement Java programs in solving complex
computing problems using concepts and features of object-
oriented programming
Midterm Coverage
Program Structure
Conditional Statements
Loop Statements
Methods
Coverage for Final

Encapsulation
Abstraction
Inheritance
Polymorphism
How To Complete This Course:
All students are expected to maintain and promote the
highest standards of personal honesty and professional
integrity. Each student has to attend lecture and laboratory
sessions within 90 hours and shall comply with the
requirements of the course before the end of the semester.
Key Topics:

 Structure Programming and its three categories


 Variable and Datatype
 Concatenation

 Java Sample Code


What is Programming ?
-to create or develop a software, which is also called software.

• Software is all around you.

• Software developers create software with the help of powerful tools called
programming languages.

• Computer programs, known as software, are instructions that tell a computer


what to do.
 Machine Language
- A computer’s native language, which differs among different types of
computers, is its machine language—a set of built-in primitive instructions. These
instructions are in the form of binary code.

 Assembly language
- Programming in machine language is a tedious process. assembly language was created in the
early days of computing as an alternative to machine languages. Assembly language uses a
short descriptive word, known as a mnemonic, to represent each of the machine-language
instructions.

An assembler—is used to translate assembly-language programs into machine code.


Example: the mnemonic add typically means to add numbers and sub means to
subtract numbers. To add the numbers 2 and 3 and get the result, you might write
an instruction in assembly code like this:

Example: add 2, 3, result


 High-Level Language

In the 1950s, a new generation of programming languages known as high-level


languages emerged. They are platform independent, which means that you can
write a program in a high level language and run it in different types of
machines. High-level languages are English-like and easy to learn and use.

 The instructions in a high-level programming language are called statements.


Example: area of a circle with a radius of 5:
area = 5 * 5 * 3.14159;
Source program or Source code - a program written in a high-
level language since a computer cannot execute a source program,
a source program must be translated into machine code for
execution.

The translation can be done using another programming tool called


an interpreter or a compiler.
 An interpreter reads one statement from the source code,
translates it to the machine code or virtual machine code,
and then executes it right away.
A compiler translates the entire source code into a
machine-code file, and the machine-code file is then
executed
?
Do not lose your motivation, if you cannot understand

everything after the first pass. In many cases, it may seem

complicated, but gradually it will be easier for you.


Where and How do I start?

Expert programmers started breaking the large


problem into smaller problems.
Where and How do I start?

Expert programmers started breaking the large


problem into smaller problems.

If you can solve small problems eventually you can


solve big problem.
Structure Programming

Structured programming, or modular programming, is a programming


paradigm that facilitates the creation of programs with readable code
and reusable components.
Types of Structured Programming
Three (3) categories

1. Procedural programming - Defines modules as procedures or functions


that are called with a set of parameters to perform a task. A procedural
language begins a process, which is then given data.
Types of Structured Programming
2. Object-oriented programming (OOP) - Defines a program as a set of objects
or resources to which commands are sent. An object-oriented language defines a
data resource and sends it to process commands.

For example:

the procedural programmer might say, "Print(object)“ , while the OOP


programmer might say, "Tell Object to Print."
Types of Structured Programming
3. Model-based programming - The most common example of this is database
query languages. In database programming, units of code are associated with
steps in database access and update or run when those steps occur. The database
and database access structure determine the structure of the code.

Requirement
Model development Code Generation
maturation phase

Models can be Code is extended to a


Testing is performed
extended and reused system-level
at every step
post verification simulation
What is Java?
Java is a popular programming language, created in 1995.t is owned by Oracle,
and more than 3 billion devices run Java.
It is used for:
 Mobile applications (specially Android apps)
 Desktop applications
 Web applications
 Web servers and application servers
 Games
 Database connection and etc.
Why Use Java?
 Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)
 It is one of the most popular programming language in the world
 It has a large demand in the current job market
 It is easy to learn and simple to use
 It is open-source and free
 It is secure, fast and powerful
 It has a huge community support (tens of millions of developers)
 Java is an object oriented language which gives a clear structure to programs and allows code to
be reused, lowering development costs
 As Java is close to C++ and C#, it makes it easy for programmers to switch to Java or vice versa
What you need to Install

1. Setting up JDK (Java Development Kit)

2. Setup IDE (Integrated Development Environment)

3. Install Eclipse or Netbeans or any,.


Java Development Kit (JDK)
- allows developers to create Java programs that can be executed by the
Java Runtime Environment (JRE).

Integrated Development Environment (IDE)


- a software used by a developer so that they can easily code in a
certain programming language, IDE has tons of features that makes
programming easier.

Ex: Netbeans , Eclipse


Review on the BASICS

Variables and Datatypes


Variables – are used to store
up temporary data to be used
in the program runtime.
Casing
Snake Case Kebab Case Camel Case

Ex. Ex. Ex.

number_of_donuts = 50 number-of-donuts = 50 numberOfDonuts = 50

fave_phrase = “Hello World” fave-phrase = “Hello World” favePhrase = “Hello World”

Pascal Case

Ex.

NumberOfDonuts = 50

FavePhrase = “Hello World”


Datatype – determines the
type of data that is assigned to
the variable.
Datatypes
1. Characters - char ‘ ’ (holds a single character or letter).
2. String – String “ ” (holds a text).
3. Boolean – Boolean (Holds true or false).
4. Integers - int (holds number).
• byte – (-128 to 127)
• short - (-32768 to 32767)
• int - (-2, 147, 483, 648 to 2,147,483,647)
• long - (9,223,372,036,854,775,808 to 9,223,372,036,854,755,807)

5. Floating Point
• float – (3.4e-038 to 3.4e + 038).
• double - (1-7e – 308 to 1.7e + 038)
Identifiers – refers to the name
of the variable that the
programmer used. It is used to
Read and Write the variable.
Rules of Identifiers
All Java variables must be identified with unique names.

• Names can contain letters, digits, underscores, and dollar signs


• Names must begin with a letter
• Names should start with a lowercase letter and it cannot contain whitespace
• Names can also begin with $ and _ (but we will not use it in this tutorial)
• Names are case sensitive ("myVar" and "myvar" are different variables)
• Reserved words (like Java keywords, such as int or boolean) cannot be used
as names
Declaring Variables

Syntax:

Datatype identifier;
Datatype identifier = value;
Concatenation
Concatenation – the process of
joining Strings together with
the plus operator.
Concatenation

“Hello” + “World” 2+5


NOT Concatenation
“3” + “5” ‘ b’ + 6

‘a’ + “b”

5+ ‘3’
Java Built-in Packages
Java API has many pre-written classes to help the programmer manage input, database and etc.

Syntax for importing specific class:

import java.util.Scanner – allow programmers to ask/ handle user input

Package name

Java is case-sensitive: "MyClass" and "myclass" has different meaning.


Topic 3.

Loops
We have three types of Loops in C++:

While Loop
Do While Loop
For Loop
Sample Java Code

public class Main {


public static void main(String[] args) {
System.out.println ("Hello World");
}
}
Note:

 The curly braces {} marks the beginning and the end of


a block of code.

 System is a built-in Java class that contains useful


members, such as out, which is short for "output".

 The println() method, short for "print line", is used to


print a value to the screen (or a file).
Topic 4.

Class and Object


Class – is a blueprint, template, or prototype. It
can describe the behaviors of its objects and is the
foundation for how the objects are built or
instantiated.

Object – is an instance of a class.


CLASS: CLASS:
MAMMAL VEHICLE

Object: Object:
Object:D
HATCHBACK SEDAN
og
Understanding CLASS & OBJECT
In soccer, players are selected from various places depending on the mastery of skills. When I
say that Ronaldo is a footballer, so you assume that Ronaldo has these basic abilities as well as
skills specific to soccer even if Ronaldo is unknown to you.

CLASS:
FOOTBALLER
CLASS:
FOOTBALLER

Object: Object:
RONALDO BECKHAM
Object:
RONALDO

State: behavior State: behavior


Demonstration
Exercise 1. Sentence Builder Challenge
Create a program that displays a STATIC sentence. Your output should
look exactly the same as given below.

Output:

Hi! My name is Jerson.


I am 25 years old.
My favorite number is 8.5.
My dream is to become a programmer.
My blood type is A.
Exercise 2. Sentence Builder Challenge
Create a program that displays a DYNAMIC sentence. Use the sample
Output below as your reference.

Sample Output:

Hi! My name is Jerson.


I am 25 years old.
My favorite number is 8.5.
My dream is to become a programmer.
My blood type is A.

You might also like