0% found this document useful (0 votes)
16 views

CSC 201 Assignm-WPS Office

Uploaded by

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

CSC 201 Assignm-WPS Office

Uploaded by

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

MODIBBO ADAMA UNIVERSITY,

YOLA
FACULTY OF PHYSICAL SCIENCE

DEPARTMENT OF COMPUTER SCIENCE

ASSIGNMENT ON

COURSE TITLE:
Computer Programming 1

COURSE CODE:
CSC 201

I.D NUMBER: PHY/20U/3891

DATE: 27th March, 2023


QUESTIONS
1. With examples list and explain the concept of OOP (Object
Oriented Programming) Language.

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

```

Public class MyInfo {


Public static void main (string[]arg) {
//Input
System.out.print (“Moses Mniyaniri”,);
Name = input.nextline();
System.out.print (PHY/20U/3891)
Matric Number = input.nextline();
System.out.print (“PHYSICS”,);
Department = input.nextline();
System.out.printIn (“200L”,);
Level = input.nextline();
}
}

```
//Output
System.out.printin(“Name:”+Matric Number:”+Department:”+Level);}
```

When we run this program, it should output:

```

Name: Moses Mniyaniri


Matric Number: PHY/20U/3891
Department: Physics
Level: 200

```

QUESTION (3): The attributes of Java Programming Language to


other High Level Language (HLL)

1. Platform-Independent: One of the most significant advantages of


Java is its platform-independence. It can run on any platform that has a
Java Virtual Machine (JVM) installed.

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 (4); Java Keyword

Java Keywords: These are the reserved or predefined words that


have a specific meaning and are used for a particular functionality in the
Java programming language. These keywords cannot be used as
identifiers or variables in a Java program.

QUESTION (5): Ten (10) Java Keywords, their Syntax and Example

S/N KEYWORD SYNTAX EXAMPLE


5
S

1. Public public public class HelloWorld


[class/method/variable] {…}

2. Private private private int variable = 0;


[class/method/variable]

3. Protected protected protected void method()


[class/method/variable] {…}

4. Abstract abstract [class/method] abstract class MyClass {


…}

5. Static static static int variable = 0;


[class/method/variable]

6. Final final final int variable = 0;


[class/method/variable]

7. Void void [method] void method() { … }

8. Class class [name] class MyClass { … }

9. Interface interface [name] interface MyInterface


{…}

10. New new [object] new MyObject();

QUESTION (6); Java Basic Data type with 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

JAVA PRIMITIVE DATA TYPES

In Java language, primitive data types are the building blocks of data manipulation. These
are the most basic data types available in Java language.

There are 8 types of primitive data types:

1. Byte: Byte data type is an 8-bit signed two's complement integer. It


has a minimum value of -128 and a maximum value of 127. Example:
byte a = 10;
2. Short: Short data type is a 16-bit signed two's complement integer. It
has a minimum value of -32,768 and a maximum value of 32,767.
Example: short b = 100;
3. Int: This data type is a 32-bit signed two's complement integer. It has
a minimum value of -2,147,483,648 and a maximum value of
2,147,483,647. Example: int c = 10000;
4. Long: This is a 64-bit signed two's complement integer. It has a
minimum value of -9,223,372,036,854,775,808 and a maximum value
of 9,223,372,036,854,775,807. Example: long d = 100000L;
5. Float: A Float data type is a single-precision 32-bit IEEE 754 floating-
point number. Example: float e = 10.5f;
6. Double: Double data type is a double-precision 64-bit IEEE 754
floating-point number. Example: double f = 10.456;
7. Boolean: Boolean data type represents only two values: true and
false. Example: boolean g = true;
8. Char: Char data type is a single 16-bit Unicode character. It has a
minimum value of 0 and a maximum value of 65,535. Example: char h
= 'A'.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy