0% found this document useful (0 votes)
23 views11 pages

Ooo Note 1

CSC 303 is a course focused on Object Oriented Programming (OOP) using Java, comparing it with Procedure Oriented Programming (POP). Prerequisites include moderate to excellent Java programming skills, and the course covers various topics such as classes, objects, methods, and Java syntax. Assessment consists of continuous evaluation (40%) and an examination (60%), with a final project involving the creation of a GPA and CGPA calculator application.

Uploaded by

nessa04nj
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)
23 views11 pages

Ooo Note 1

CSC 303 is a course focused on Object Oriented Programming (OOP) using Java, comparing it with Procedure Oriented Programming (POP). Prerequisites include moderate to excellent Java programming skills, and the course covers various topics such as classes, objects, methods, and Java syntax. Assessment consists of continuous evaluation (40%) and an examination (60%), with a final project involving the creation of a GPA and CGPA calculator application.

Uploaded by

nessa04nj
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/ 11

CSC 303 (OBJECT ORIENTED PROGRAMMING)

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

This is a programming paradigm that was derived from structured programming. It is


based upon the concept of procedure calls. Procedures, also known as routines, subroutines
or functions, simply consist of a series of computational steps to be carried out. During a
program’s execution, any given procedure might be called at any point, including by other
procedures or itself. The computer processors provide hardware support to procedural
programming through a stack register and also provide instructions for calling procedures
and returning from the stack. Some of the first procedural programming languages were
Fortran, ALGOL, COBOL, C, Pascal etc.

Why did OOP Paradigm emerge?

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.

The Object Oriented Paradigm


The objected oriented programming paradigm arose out of the need to move from creating
simple computer programs to creating complex computer software. It was based on the
concepts of “objects” which contains data (also known as attributes or properties) in the
form of fields, and code that is in the form of procedures (also known as methods). The
main target of this paradigm was being able to write or compose software and software
components that were understandable, reusable, maintainable, and adaptable. It drew
heavily from the engineering concepts of systems design and construction.
Object-oriented programming (OOP) languages were designed to overcome the problems
encountered with procedural languages in the following ways:
1. The basic unit of OOP is a class, which encapsulates both the static
properties/attributes and dynamic operations within a "box", and specifies the
public interface for using these boxes. Since classes are well-encapsulated, it is
easier to reuse these classes. In other words, OOP combines the data structures and
algorithms of a software entity inside the same box.
2. OOP languages permit a higher level of abstraction for solving real-life problems.
The traditional procedural language (such as C and Pascal) forces you to think in
terms of the structure of the computer (e.g. memory bits and bytes, array, decision,
loop) rather than thinking in terms of the problem you are trying to solve. The OOP
languages (such as Java, C++ and C#) let you think in the problem space, and then to
use software objects to represent abstract entities of the problem space to be solved.

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

Object-Oriented programming has many benefits:

 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

Java is well-known as a programming language for Internet applications. However, we are


going to consider Java as a general-purpose programming language that is suitable for
almost any application, whether it involves the Internet or not. The first version of Java was
not used for writing internet application or a general purpose applications, but it evolved
into both. In 1991, James Gosling led a team at Sun Microsystems that developed the first
version of Java (which was not yet called Java). This first version of the language was
designed for programming home appliances, such as washing machines and television sets.
Although that may not be a very glamorous application area, it is no easy task to design
such a language. Home appliances are controlled by a wide variety of computer processors
(chips). The language that Gosling was designing needed to work on all these different
processors. Moreover, a home appliance is typically an inexpensive item, so the
manufacturer would be unwilling to invest large amounts of money into developing
complicated compilers. To simplify the tasks of writing compilers (translation programs)
for each type of appliances, the team used a two-step translation process. The programs are
first translated into an intermediate language that is the same for all appliances (or all
computers), and then a small, easy-to-write and hence, inexpensive program translates this
intermediate language into the machine language for a particular appliance or computer.
This intermediate language is called Java bytecode, or simply, byte-code. Since there is
only one intermediate language, the hardest step of the two-step translation from program
to intermediate language to machine language is the same for all appliances (or all
computers); hence, most of the cost of translating to multiple machine languages was
saved. The language for programming appliances never caught on with appliance
manufacturers, but the Java language into which it evolved has become a widely used
general purpose programming language. Today, Java is owned by Oracle Corporation, which
purchased Sun Microsystems in 2010.

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.

Java can be broadly described as a:

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.

4. Concurrent high level programming language (Multi - threading): This enables


programs to perform multiple operations/tasks at (or around) the same time.

5. Language that runs very fast.

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.

Principles used in developing the Java Language.

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.

Fig 1: The Java Program Translation Process.


SAMPLE JAVA CODE

public class First


{
public static void main(String[] args)
{
System.out.println("First Java application");
}
}

Fig 2: Analysis of the Sample Java Statement.


The string “First Java application” appears within parentheses because the string is an
argument to a method, and arguments to methods always appear within parentheses.
Arguments are pieces of information that are sent into a method, usually because the
method requires the information to perform its task or carry out its purpose. The act of
sending arguments to a method is called passing arguments to the method.

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.

Within the statement System.out.println("First Java application");, out is an object that is a


property of the System class that refers to the standard output device for a system,
normally the monitor. The out object itself is an instance of the PrintStream class, which
contains several methods, including println(). Technically, you could create the out object
and write the instructions within the println()method yourself, but it would be time
consuming, and the creators of Java assumed you frequently would want to display output
on a screen. Therefore, the System and PrintStream classes, the out object, and the println()
method were created to make it easy to display contents on the screen.

Within the statement System.out.println ("First Java application");, System is a class.


Therefore, System defines attributes for System objects. One of the System attributes is out.
(You can probably guess that another attribute is in and that it represents an input device.).

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.

Basic Syntax of a Java Program.


Everything (objects, methods, data) that you use within a Java program must be part of a
class. When you write public class First, you are defining a class named First. You can define
a Java class using any name or identifier you want, as long as it meets the following
requirements:
1. A Java identifier must begin with a letter of the English alphabet, a non-English letter
(such as α or π), an underscore, or a dollar sign. A class name cannot begin with a digit.
2. A Java identifier can contain only letters, digits, underscores, or dollar signs.
3. A Java identifier cannot be a reserved keyword, such as public or class.
4. A Java identifier cannot be one of the following values: true, false, or null. These are not
keywords (they are primitive values), but they are reserved and cannot be used.

You might also like