CSC 201 Assignm-WPS Office
CSC 201 Assignm-WPS Office
YOLA
FACULTY OF PHYSICAL SCIENCE
ASSIGNMENT ON
COURSE TITLE:
Computer Programming 1
COURSE CODE:
CSC 201
1
2. Write a Java program to display; Your Name, Matriculation
Number, Department and with your Level on a sprat line when
the code will be writing in a single line.
3. What are the attributes of Java programming language to other
High-Level Language (HLL)?
4. Discuss extensively what you understand by the Java keyword.
5. Write 10 Java keywords with their syntax and example.
6. Explain Java basic data type with examples.
ANSWERS
QUESTION (1); Concept of OOP (Object Oriented Programming)
Language
The Concept of OOP (Object Oriented Programming)
Language is to provide a programming paradigm that is based on
the concept of objects. An Object is an instance of a class, which is
a blueprint that defines the properties and behaviors of that object.
In an OOP language, all data and code are organized into objects,
which are instances of classes. Class is a blueprint that defines the
properties and methods of an object.
There are four (4) fundamental concepts of OOP language they
are:
1. Encapsulation
2. Inheritance
3. Polymorphism
4. Abstraction
Definition of Concepts:
1. Encapsulation: This is the concept of hiding the internal
implementation details of an object and exposing only the
necessary information to the outside world.
Example of Encapsulation in OOP is a class called `car`, A `car`,
object can have a set of attributes such as 'make, model, year, and
2
`mileave`. If we don’t want other classes to be able to access or
modify these attributes directly, so we encapsulate them by making
them private or protected. We provide public methods, such as
`get–make()`, `get Year()` and `getMileage ()` to access the value
of these attributes.
2. Inheritance: This is the concept of creating new classes that are
derived from existing classes. The new class inherits the properties
and methods of the base class and can also add its own properties
and methods. Inheritance allows you to create more specialized
classes without duplicating code.
Example of Inheritance in OOP is creating a vehicle like `Car` `
Motorcycle`, `Truck` etc. The vehicle class will have common
properties and methods that all types of vehicles have, like ` make`,
` model`, ` year`, getMileage()`, ` accelerate()`, `brake`, and so on.
3. Polymorphism: This is the concept of using the same interface to
represent objects of different classes. Polymorphism allows you to
write more flexible and reusable code that can work with different
types of objects.
Example of Polymorphism in OOP is creating a ‘Shape’ class with
a ‘calculateArea()` method, and then creating multiple subclasses of
‘Shape’ like `Circle`, `Square` and `Triangle`. Each sub-class will
implement the `calculateArea()’ method in a unique way that is
appropriate for that specific shape.
4. Abstraction: This is the concept of representing complex systems
by simplifying them into smaller, more manageable components.
Abstraction helps to reduce complexity, make code easier to
understand, and improve maintainability.
Example of Abstraction in OOP is creating an abstract class
`Animal’ which contains common properties and methods that all
animals have, but doesn’t provide any implementation for those
3
methods. Instead, the implementation will be provided by each
subclass of `Animal’.
QUESTION (2); Java Program
```
```
//Output
System.out.printin(“Name:”+Matric Number:”+Department:”+Level);}
```
```
```
4
2. Object-oriented: Java is an object-oriented programming (OOP)
language which supports the concepts of encapsulation, inheritance,
and polymorphism.
3. Robust: Java is a robust programming language that provides strong
memory management, exception handling, and automatic garbage
collection.
4. Secure: Java is inherently secure, as it provides a robust security
model for its runtime environment, including security features like
access control, byte-code verification, and class loading.
5. Simple: Java provides a simple and easy-to-learn syntax, which makes
it easy to understand and implement.
6. Portable: Java code is portable, meaning that it can be written on one
platform and run on another without any modifications.
7. Interpreted: Java is an interpreted language, which means that code
can be executed directly without the need for compilation.
8. Scalable: Java provides scalability options for a wide range of
applications, from small standalone applications to large enterprise-
level applications.
9. High-Performance: Java is a high-performance programming
language that can handle complex applications with ease.
10. Multithreaded: Java is a multithreaded programming language
that allows multiple threads to run concurrently.
QUESTION (5): Ten (10) Java Keywords, their Syntax and Example
Java Basic Data Types: specify the different sizes and values that can be stored in
the variable.
There are two types of Java Basic data types, they are:
6
1. Primitive data types: The primitive data types include boolean, char, byte, short, int,
long, float and double.
2. Non-primitive data types: The non-primitive data types include Classes, Interfaces, and
Arrays
In Java language, primitive data types are the building blocks of data manipulation. These
are the most basic data types available in Java language.