2023 Assesment Exam Flashcards

1
Q

Define syntax

A

refers to the set of rules that define the structure of a program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define Java API

A

Application Programming Interface, is a collection of pre-written software components that developers can use in their Java programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define a Variable

A

a named storage location in memory that holds a value during program execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define source code

A

the set of instructions written by a programmer using the Java programming language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define an Algorithm

A

set of well-defined instructions that are executed in a specific order to solve a particular problem

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

State examples of eselctive control structures

A

sequence , The If statement , the Switch(case) statement , iteration loops(For Loop, Do-while loop, while loop)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Assume that there is a java class called Test and it has not been compiled but we want to run it.
i. Identify the appropriate command to use to compile this class on command line interface.

A

javac Test.java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Assume that there is a java class called Test and it has not been compiled but we want to run it.

A

java Test

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Use one java instruction to write a statement that displays the following output on the screen.
Hello
World

A

System.out.println(“Hello”+”\n”+”World”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Identify (3) rules which a programmer must consider when using a loop that should terminate at some point.

A
  1. INITIALIZE the loop control variable outside the loop
  2. Use the loop control variable as a variable in the loop
  3. Alter the loop control variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Identify a loop which should be used in a situation where it should execute at least once.

A

Do while statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Justify why statements in the body of a loop must be indented.

A
  • Improve legibility
  • Improve readability
  • Neatness
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Define Sub routines

A

Methods are essentially self-contained blocks of code that perform specific tasks within a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Define a constructor

A

a constructor is a special type of method that is called automatically whenever you create an object of a class using the “new” keyword.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Give an example demonstrating how subroutines/methods are defined in Java

A

public static void add(int a, int b ){
int sum;
sum = a + b;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Differentiate between a void and non-void subroutine?

A

A void method does not return a value while a non void returns a value.

17
Q

Why is it important to use parameterized constructors.

A

because they allow you to create objects with specific initial values, making your objects more flexible and customizable.

17
Q

What is the purpose of assignment operators in Java? Give an example.

A

assign values to variables. e,g
int age = 25

17
Q

How can you use the += operator in Java to increment a variable’s value by a specified amount? Give an example.

A

The += operator in Java is a shorthand way to increment a variable by a specified amount. It combines addition and assignment.
e,g
int count = 5;
count += 3; // Equivalent to count = count + 3; // Now count will be 8

18
Q

What is implicit cast in Java? Provide an example of implicit

A

Implicit casting (widening conversion): Automatic conversion of smaller data types to larger ones (e.g., int to double). No data loss, happens automatically.

int x = 10; double d = x; // No cast needed

19
Q

What is explicit cast in Java? Provide an example of explicit.

A

Explicit casting (narrowing conversion): Manual conversion of larger data types to smaller ones (e.g., double to int). Possible data loss, requires the cast operator (type).

double d = 3.14; int x = (int) d; // Possible data loss (decimal part truncated)

20
Q

Define a literal in Java and provide examples of 5 different types of literals.

A

A literal in Java is a fixed value directly written in your code. It represents a constant data that cannot be changed during program execution.
e,g ; integer , character , String , Double , Float, Boolean.

21
Q

explain 4 primitive data types

A

Primitive Data Types: These are basic building blocks that hold specific data types and have predefined sizes in memory.:

byte: Stores small whole numbers (8 bits).
short: Stores whole numbers (16 bits).
int: Stores whole numbers (32 bits, commonly used).
long: Stores large whole numbers (64 bits).

22
Q

explain reference data types

A

Non-primitive Data Types: These are reference types that refer to objects in memory. They are more complex and user-defined. Examples include:

String: Represents text data.

23
Q

you didnt do arrays and coding questions boy!!

A