0% found this document useful (0 votes)
26 views13 pages

Week 1 - CM - MDL - CS213

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

Week 1 - CM - MDL - CS213

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

ASIAN INSTITUTE OF COMPUTER STUDIES

Bachelor of Science in Computer Science


Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

MODULE 1: OBJECT ORIENTED PROGRAMMING


WEEK 1

Learning Outcomes:
After completing this course you are expected to demonstrate the following:
1. Discuss the core concepts and main features of OOP and explain the object oriented
approach. Discover the history of Java, its key features, and how the Java technology
works.

A. Engage
Trivia
The earliest version of Java was known as Oak. This was inspired by a big oak tree that grew
outside the window of the lead creator of Java, James Gosling. It was later changed to Java
by Sun’s marketing department when Sun lawyers found that there was already a computer
company registered as Oak.
B. Explore
Video Titles:
1. What’s a Programming Language?
2. OOP
3. History of Java
YouTube Links:
1. https://youtu.be/NUl8lcbeN2Y
2. https://youtu.be/qwS-BCOCB-A
3. https://youtu.be/DcQPtlFlgzY
Module Video Filenames:
1. Introducing object-oriented programming_WEEK1
2. OOP Infographic Animation_WEEK1
3. History of Java_WEEK1

C. Explain

Everything in OOP is arranged as self-sustainable “objects”, it was developed as a result of


restrictions in earlier approaches to programming.

1. Describe and explain object-oriented programming as a programming approach


based on objects and classes.
2. Identify and describe each object oriented programming languages in building
applications and software sulotions.
3. Distinguish the application of OOP in real-business system.
4. Evaluate the main features in OOP
5. Articulate the benefits when it comes to software development.

Basic concepts relating to the Java architecture and language semantics.


1. Define and describe the history and key features of Java.
2. Recognize the key components of the Java Runtime Environment (JRE) and how
they collaborate.
Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 1 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

3. Examine the different types of Java platforms and applications.


4. State the basic concepts of the Java language structure.
5. Identify the primitive Java data types and how they are used.

D. Elaborate

Why Learn About Object Oriented Programming?

Figure1.1

Benefits of OOP

1. It is easy to model a real system as real objects are represented by programming


objects in OOP. The objects are processed by their member data and functions. It is
easy to analyze the user requirements.
2. With the help of inheritance, we can reuse the existing class to derive a new class such
that the redundant code is eliminated and the use of ex existing class is extended. This
saves time and cost of program.
3. In OOP, data can be made private to a class such that only member functions of the
class can access the data. This principle of data hiding helps the programmer to build a
secure program that ccannot
annot be invaded by code in other part of the program.
4. With the help of polymorphism, the same function or same operator can be used for
different purposes. This helps to manage software complexity easily.
5. Large problems can be reduced to smaller and more manageable problems. It is easy to
partition the work in a project based on objects.
6. It is possible to have multiple instances of an object to co co-exist without any
interference i.e. each object has its own separate member data and function.

Application of OOP
 OOP is now one of the programming buzzwords today. There seems to be a great deal
of interest and excitement in using OOP among software engineers. Uses of OOP are
beginning to get value in many places. The most popular application of object
object-oriented
programming, up to now, has been in the place of user interface design for example
window. Hundreds of windowing systems are developed, using the OOP techniques.

Prepared and
nd Validated By: Ms. Ruth L. Tarraya, B
BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 2 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

Real-Business System
 Are generally much more complex and contain many more objects with complicated
attributes and approach. OOP is useful in these types of application because it can
simplify a complex problem. The bright areas of application of OOP include:

1. Simulation and modeling


2. Object-oriented data bases
3. Real-time system
4. Hypertext, Hypermedia, and expert Ext
5. Neural networks and parallel programming
6. Decision support and office automation systems
7. AI and expert systems
8. CIM/CAM/CAD systems

Object Oriented Programming (OOP)


 The term used to describe a programming approach based on objects and classes.
 The object-oriented paradigm allows us to organize software as a collection of objects
that consist of both data and behavior. This is in contrast to conventional functional
programming practice that only loosely connects data and behavior.
 This involves taking an approach that is more mindful of data and less concerned with
logic, which is more commonly the case in other programming paradigms.
 The view of objects and actions is the reverse of how it is in other languages, and the
emphasis is on the objects themselves rather than on the execution of tasks that
employ the objects.
 Also helps to sort objects in a manner that allows for polymorphism to take place. That
is, different objects will be able to respond to a common message, but each in a
different way that is unique to that object.

Designing computer software


 With object oriented programming begins with defining the objects that are to be
manipulated by the program. The Programmer will then begin to identify the
relationship between each object, a process usually referred to as data modelling.
Essentially, the Programmer is seeking to place the objects into a classification,
therefore helping to define the data that is part of the inheritance brought to the task
by each object.

Advantages of Object Oriented Programming


 The process makes good use of modularity, meaning that objects and tasks are
grouped in a way that each module is capable of independent consideration. This can
be a great help when making enhancements to a program, as modularity makes it
possible to address the task of making alternations to the setup of one portion of the
programming without affecting the structure and function of the other modules.

Since the 1980s the word ‘object’ has appeared in relation to programming languages, with
almost all languages developed since 1990 having object-oriented features. Some languages
have even had object oriented features retro-fitted. It is widely accepted that object-oriented
programming is the most important and powerful way of creating software.

Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 3 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

The object-oriented programming approach encourages:


- Modularization: where the application can be decomposed into modules.
- Software re-use: where an application can be composed from existing and new
modules.

An object-oriented programming language generally supports five main features:


1. Classes
2. Objects
3. Encapsulation
4. Inheritance
5. Polymorphism
6. Abstract Classes
7. Object-Oriented Analysis and Design

If we think of a real-world object, such as a television (as in Figure 1.2), it will have several
features and properties:
1. We do not have to open the case to use it.
2. We have some controls to use it (buttons on the box, or a remote control).
3. We can still understand the concept of a television, even if it is connected to a DVD
player.
4. It is complete when we purchase it, with any external requirements well documented.
5. The TV will not crash

Figure 1.2 the concept of a class - television

A class should:
- Provide a well-defined interface - such as the remote control of the television.
- Represent a clear concept - such as the concept of a television.
- Be complete and well-documented - the television should have a plug and
should have a manual that documents all features.
- The code should be robust - it should not crash, like the television.

The object-oriented model should provide advantages over the other models, especially as the
library of components that is developed grows over time.

Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 4 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

Figure 1.3

A Short Java History

In 1991, Sun Microsystems funded the research project called “Green” to design a
programming language to be used in intelligent consumer electronic devices, like televisions,
VCRs, and washing machines. Since home appliance processor chips change on a continuous
basis, the programming language used needed to be extremely portable. Existing
programming languages such as C++ were clearly not suitable. Often, the embedded language
was tied closely to the appliance processor, an
and
d a new language needed to be developed. This
new language was originally termed Oak (referring to the tree that was outside the main
developer’s, James Gosling’s, window), but was quickly renamed Java. The use of Java for
home appliance applications turne
turned
d out to be initially unsuccessful, but the emergence of the
Web gave it a new future. In 1994, the first Java
Java-enabled
enabled web browser HotJava was developed.
A year later, Netscape incorporated Java support into its web browser. Other companies
quickly followed
d and Java’s popularity rapidly rose. Sun released Java 1.0 to the public in 1995.
In 2007, Sun made Java’s core code available as open source under the terms of the GNU
General Public License (GPL). In 2009, Sun was acquired by Oracle, which is currently
continuing the development of Java. Table 22-1 1 gives an overview of the major releases,
together with some key characteristics. Note that the versions were originally referred to as
JDKs (Java Development Kits) and later rebranded into J2SE (Java 2 Platform Platform, Standard
Edition).

Prepared and
nd Validated By: Ms. Ruth L. Tarraya, B
BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 5 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

Table 1.1 Characteristics of Major Java Releases

Features of Java
The key characteristics of the Java programming language that have made it so popular include
the following:
1. Simple: Java omits some of the vaguely defined features of C++. It has facilities for
automatic garbage collection to automatically release unused memory while a program
is running. It also includes a rich predefined set of packages (such as for mathematics,
statistics,
istics, database access, GUI design, and so on) that can be easily reused by
application developers. Its syntax looks very similar to C/C++, making it easy for
experienced programmers to learn and use.
2. Platform independent and portable: By using a hybrid compilation/interpretation
c
approach, Java programs can be executed in a networked environment with different
hardware platforms and architectures. This also makes Java applications extremely
portable, effectively realizing the “write once, run everywhere” pphilosophy.
3. Object-oriented: Java implements the object-oriented oriented programming paradigm by
grouping data and operations into classes and/or objects.
4. Secure: Java has many facilities to guarantee security in a networked environment. It
imposes various types of access restrictions to (networked) resources and carefully
supervises memory allocation. It allows code to be downloaded over a network and
executed safely in the confined spaces of memory. It also foresees extensive capabilities
for configuring security levels.
5. Multi-threaded: Java delivers the power of advanced multi multi-threaded capabilities to the
developer in an environment without complexity. More specifically, Java code can be
run concurrently as multiple threads in a process, in order to improve its ex execution
performance.

Prepared and
nd Validated By: Ms. Ruth L. Tarraya, B
BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 6 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

6. Dynamic: Java allows code to be added to libraries dynamically and then can determine
which code should run at execution time. It also foresees a strict separation between
interface and implementation.

Looking Under The Hood take a look under the hood of Java. (Java bytecode, the Java Runtime
Environment (JRE), and Java platforms and applications)
Bytecode

 every Java source program (BMI.java) is compiled into an intermediate language called
bytecode (BMI.class), which is platform independent. During this compilation step,
errors in the code can be reported.
 Java bytecode is not native machine code, so it cannot be run as such on a host
computer.
 Instead, the bytecode will be parsed by a platform-specific interpreter in order to run it
on a particular architecture, such as on Windows, Linux, Mac OS, Sun Solaris, and so on.
 Can be considered as machine code for the JVM.

JVM (Java Virtual Machine)


 is basically a virtual CPU complete with its own operation codes. Irrespective of which
platform you are on, the bytecode is the exact same. The JVM is then a separate process
that runs on top of a native processor.

Java runtime environment (Jre)


 is the software environment in which Java programs run.

The next subsections elaborate on the following components:


1. Java API (Application Programming Interface)
2. Class loader
3. Bytecode verifier
4. Java Virtual Machine (JVM)

Figure 1.4 Java Runtime Environment

Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 7 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

Java Application Programming Interface (API)


 is the set of prepackaged, ready-made Java components grouped into libraries.
 It provides programmers with many useful capabilities.

Some popular API libraries are listed in Table 1.2

Table 1.2 Example Libraries from the Java API

When developing new Java applications, it is important to consider the API to see if you can use
some of the functionalities that are already implemented. This saves you from having to
program every aspect yourself, and it can also make your program more recognizable and
usable to other programmers. The API is flexible and open, which means that new packages or
libraries can be added to it on an ongoing basis.

Class Loader
 The class loader locates and reads the *.class files needed to execute the Java program
and loads the bytecodes into memory. To safeguard a secure execution, it can assign
different portions (namespaces) of memory to locally versus remotely obtained classes.
Classes are typically assembled into libraries that are stored physically in JAR (Java
Archive) files. The libraries may have been written by the user or obtained externally. In
order to locate the classes, the class loader will first find the corresponding libraries and
then load the classes as they are needed by the program (called ondemand loading).

The class loader basically has three subcomponents:

1. Bootstrap class loader


2. Extensions class loader
3. System class loader

Bytecode Verifier
 The bytecode verifier checks to make sure the bytecodes are valid without breaching
any of Java’s security rules. It pays special attention to type checking all the variables
and expressions in the code and ensures that there is no unauthorized access to

Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 8 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

memory. Note that when a Java program is invoked, you can choose to disable the
bytecode verifier (which will make it run slightly faster), enable it only for code that was
downloaded remotely from the network, or enable it for all the code. Once the code is
verified, it will be offered to the Java Virtual Machine (JVM) for interpretation.

Java Virtual Machine (JVM)


 The Java Virtual Machine (JVM) can be considered an abstract computer machine
capable of executing bytecode on a particular hardware platform. It constitutes the
heart of the “write once, run everywhere” philosophy. Various JVM implementations
have been provided for various hardware and/or operating system environments. The
most popular JVM is HotSpot produced by Oracle. It is available for Windows, Linux,
Solaris, and Mac OS X. A key component of the JVM is the interpreter responsible for
interpreting the bytecode instructions. The garbage collector cleans up unused memory
to improve the efficiency of the program. The JVM typically also includes facilities for
multithreading and synchronization, whereby a Java program can be executed in one or
more parallel execution paths (threads) scheduled on one or more CPUs, hereby
significantly accelerating its execution time.

Java platforms
 A Java platform or edition consists of a JRE with a specific set of libraries for a specific
application environment.

Table 1.3 gives an overview of the most important Java platforms.

Table 1.3 Java Platforms

Java applications
 standalone applications
 Java applets
 Java servlets
 Java beans

Java Language Structure


Let’s consider the following running example of a Java program calculating BMI to
illustrate the discussion.

Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 9 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

The program contains several statements, each ending with a semicolon (;). A statement
performs a specific action and can span multiple lines.
 First, note that Java is a form-free language and does not require special
indentation.
 Any statement can start at any place of indentation.
 Also, extra whitespace, tabs, and new lines are ignored by the compiler. The
program can thus be formatted in many ways. To improve the readability of your
code, it is highly recommended that you use a consistent formatting style.
Classes

 A class is thus a code container.


Identifiers

 An identifier is a name of a language element. This can be a class, variable, or


method.
Java Keywords
Table 1.4 lists the 50 keywords of Java. All these keywords have a special reserved meaning in
Java and thus cannot be used as identifiers.

Table 1.4 Java Keywords

Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 10 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

Variables

 A variable is a name for a memory location that stores a specific value.

Methods
 Is a piece of code within a class definition, and it performs a specific kind of
functionality.
Java Data Types

 Java is a strongly typed language. This means that every variable should first
be carefully declared upfront before it can be used.
Primitive Data Types

 Java supports eight built-in primitive data types. If the user has not initialized
a variable, the compiler will automatically assign the default value. Note that
the ranges and default values are uniform and do not depend on the
underlying machine architecture on which the Java program runs.

Table 1.5 defines each of these and specifies the range and default value.
Table 1.5 Java Primitive Data Types

Literals

 A literal is a value assigned to a variable of a specific type.

An example of this is:


weight = 60; height = 1.70;
In this example, the equals sign (=) is used as an assignment operator to assign the literals
60 and 1.70 to the variables weight and height, respectively.
Here are some other examples of literals:
boolean overweight = true;
short age = 38;
character initial = 'B';

Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 11 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

Note that literals of type long, float, and double can end with the letters L/l, F/f, and D/d,
respectively. Floating point literals can also be expressed in scientific notation using E or e.

This is illustrated here:


Double bmi = 24.2;
Double bmi = 24.2d;
Float bmi = 0.242e2;

Character literals (char) are always enclosed in single quotes and may contain any Unicode
character (see www.unicode.org for more details).

An example of this is as follows:


char gbPoundUniSymbol = '\u00A3';
char gbPoundSymbol = '£';
char dollarUniSymbol = '\u0024';
char dollarSymbol = '$';

Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 12 of 13
ASIAN INSTITUTE OF COMPUTER STUDIES
Bachelor of Science in Computer Science
Course Modules
CS213 – Object Oriented Programming
2nd Year – 1st Semester

E. Evaluation
ASSESSMENT:
Instructions: You may write your answer on the Answer Sheet (AS) provided in this module.

CONTENT FOR ASSESSMENT:


1. Enumerate and explain the main features of object-oriented programming.
2. Explain the use and benefits of OOP in software development.
3. In your opinion, what are the difference between procedural and object-oriented
programming?
4. Define and explain the use of literals
5. What is the importance of object oriented programming in real world?
6. In your opinion, How the Java technology works?
7. Explain the basic concepts of the Java language structure?
8. Define the relationship between Java and JavaScript?
9. Describe the different types of Java platforms and applications
10. Define and explain the primitive Java data types

References:

1. Core Concepts in Computer Science: Object Oriented Programming (OOP), 3G ELearning


LLC, 2019
2. Core Concepts in Computer Science: JAVA Programming, 3G E-Learning LLC, 2019
3. YouTube link: https://youtu.be/NUl8lcbeN2Y
4. YouTube link:https://youtu.be/qwS-BCOCB-A
5. https://www.udemy.com

Facilitated By:
Name :
MS Teams Account (email) :
Smart Phone Number :

Prepared and Validated By: Ms. Ruth L. Tarraya, BSCS | Dean Manuel Luis C. Delos Santos, MSCS Page 13 of 13

You might also like