Ooo Note 1
Ooo Note 1
COURSE DESCRIPTION
This course takes an in-depth look into Object Oriented Programming using Java. It
introduces and presents a brief comparison between OOP and POP as programming
paradigms.
COURSE PREREQUISITES
This course requires moderate to excellent programming capability using Java.
COURSE TOOLS AND MATERIALS:
Student must have a functioning Laptop with moderate to high processor capacity.
The Java Virtual Machine (available at oracle.com)
An IDE (preferably Intelli J Idea) available at jetbrains.com
CSC Practical Workbook
COURSE GRADING
Continuous Assessment (Course Project, Assignments, Test, Attendance) : 40%
Examination: 60%
Kindly note that grading of Course project, assignments, test and examination is STRICTLY
subject to class attendance.
COURSE CONTENT
1. The Object Oriented (OOP) Paradigm
2. Procedure Oriented Programming (POP) Paradigm
3. Introduction to Java Programming Language
a. A simple Java Program
b. Understanding Blocks and Scopes
c. Data types and Variables
d. Strings
e. Control Structures (Selection, Repetition and Iteration)
f. Arrays
g. Java Applets
4. Attributes of Object Oriented Programming
5. The concept of Classes, Objects and Methods in Object Oriented Programming.
6. Graphical Input/Output (Introduction to Java FX)
7. Final Class Project:
An application for calculating gpa and cgpa using scores from courses taken.
Method:
Design an eye catching interface for the application in figma and export to Android
Studio for coding.
What is a Paradigm:
Programming paradigm is the classification of programming languages based on their
inherent characteristic. There are a number of programming paradigms some of which are
Object Oriented paradigm, procedural paradigm, declarative paradigm, logical paradigm.
Procedural Programming
In the engineering disciplines, hardware components such as computers and cars, for
instance, are assembled from parts. These parts are known (understandable), reusable and
maintainable hardware components. Meanwhile, in the computer science discipline, it was
very difficult to "assemble" an application from software components in spite of the fact
that millions of well written, tested, and documented programs and routines existed. For
each new application, the wheels had to be re-invented by writing the program from
scratch.
The major reason for this was because the traditional procedural oriented programming
languages could not be used to create the desired reusable software components owing to
some notable drawbacks which include:
a) The procedure oriented programs are made up of functions and by design, functions
are not really reusable. It is very difficult to copy a function from one program and reuse it
in another program as is because such a function may have been written to reference global
variables and other functions. In other words, functions are not well-encapsulated (that is
the data the function is to operate upon is not contained or concealed within the same
space) as a self-contained reusable unit.
b) The procedure oriented languages do not support the constructs required for high-
level abstraction needed for solving real life problems. For example, C programs uses
constructs such as if-else, for-loop, array, method, pointer, which are low-level constructs
that are not suitable for abstracting real problems such as large or complex software
systems.
c) The procedural-oriented languages focus on procedures, with function as the basic
unit. You need to first figure out all the functions and then think about how to represent
data that the functions are supposed to work on.
3. The object-oriented languages focus on components that the user perceives, with
objects as the basic unit. You figure out all the objects by putting all the data and
operations that describe the user's interaction with the data.
As an example, suppose you wish to develop a computer soccer game (which is
considered to be a complex application). It is quite difficult to model the game in
procedural oriented languages. But using OOP languages, you can easily model the
program according to the "real objects" that appear in the soccer games. These real
objects can be represented as:
Player: attributes include name, number, location in the field etc; operations(actions)
include run, jump, kick-the-ball etc.
Ball:
Referee:
Field:
Audience:
Weather:
Scoreboard:
After using these objects to model the soccer game in question, some of the resulting
classes (such as Ball and Audience) can be reused in another related application, like a
computer basketball game, with little or no modification
Ease in software design: OOP allows you to think in the problem space rather than the
machine's bits and bytes. This high-level of abstraction eases the design of software
which in turn leads to more productive software development.
Ease in software maintenance: OOP employs the modular software development process
which makes for easy understanding and isolation of software bundles, and hence
resulting in software systems that are easy to test, debug, and maintain.
Reusable software: The main motivation behind the OOP concept is code reuse. OOP
supports the building of reusable code components. In fact, all modern OOP have huge
code libraries that are growing by the day.
Introduction to Java
Things that are called procedures, subroutines, functions, or subprograms in other languages
are all called methods in Java. In Java, all methods (and for that matter, any programming
constructs whatsoever) are part of a class. Java application program is a class with a
method named main; when you run the Java program, the run-time system automatically
invokes the method named main.
Note: Java applets and applications are two kinds of common Java programs. An
application is just a regular program. Although the name applet may sound like it has
something to do with apples, it really means a little Java application, not a little apple.
Applets and applications are almost identical. The difference is that applications are meant
to be run on your computer like any other program, whereas an applet is meant to be run
from a Web browser, and so can be sent to another location on the Internet and run there.
1. General – Purpose: This implies that it is not constrained to one particular domain. It
can be used to develop wide varieties of applications
2. Object – Oriented: This makes it possible (easy) to model real – world scenarios in a
more natural way.
3. Platform – independent: Java’s mantra is WORA. This implies that any program written
in Java can be run on any platform regardless of the OS and architecture.
Java was initially developed to run inside embedded systems and later within browsers in
the form of java programs called applets. However, it soon evolved as a popular language for
developing large scale web applications, standalone desktop applications and mobile
applications. Java provides separate dedicated platforms for these types of applications.
1. Familiar Syntax: Java was invented in the mid-90s and most programmers at this time
were using C and C++. Thus, Java’s designers kept the syntax familiar and similar to that
of C and C++.
2. Simple and Safe: Simplicity was one of the most important goals for Java’s designers. In
contrast to C and C++, they wanted Java to be easier to use. Therefore, Java doesn’t have
many features that made C and C++ complex, confusing and unsafe.
3. Secure: A Java program can be downloaded from across the network and should not
cause any harm to the user’s computer.
4. Rich Library: This includes extensive predefined functionalities. This is the Java API. It
helps programmers to focus on writing new logic without having to reinvent the wheel.
i.e. Programmers can make use of the predefined functionalities written by experts and
have already been used by millions of programmers.
Within the statement System.out.println("First Java application");, the method to which you
are passing "First Java application" is named println(). The Java methods println() and
print() both produce output. With println(), after the output is displayed, the insertion
point moves to the next line. (The insertion point is the point at which the next output
appears.) With print(), however, the insertion point does not advance to a new line; it
remains on the same line as the output. When you call a method, you always use
parentheses following the method name.
The dots (periods) in System.out.println() are used to separate the names of the
components in the statement. You will use this format repeatedly in your Java programs.
Java is case sensitive; the class named System is a completely different class from one
named system, SYSTEM, or even sYsTeM, and out is a different object from one named Out
or OUT.
You must pay close attention to using correct uppercase and lowercase values when you
write Java programs. So, the statement that displays the string “First Java application”
contains a class, an object reference, a method call, a method argument, and a statement-
ending semicolon, but the statement cannot stand alone; it is embedded within a class, as
shown in the sample first program.