Computer Knowledge

Programming Fundamentals

2,611 Questions

Programming fundamentals form the core logic of software development and computer science. This includes variable declarations, pointer assignments, loop iterations, and exception handling. These technical topics are regularly tested in computer knowledge and IT officer competitive examinations.

Variables and arraysPointer assignmentsLoop iterationsException handling blocksCompile time errorsFunction references

Programming Fundamentals Questions

Multiple choice technology programming languages
  1. No. You can write a program to catch just the exceptions you want.

  2. No. But if a program catches one type of exception it must catch all other types as well.

  3. Yes. If a program is not written to catch all exceptions it will not compile.

  4. Yes. A program can not do I/O unless it catches all exceptions.

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Java only requires catching checked exceptions. Runtime exceptions (RuntimeException and its subclasses) can be caught or ignored. A program can selectively catch only the exceptions it wants to handle.

Multiple choice technology programming languages
  1. Some of the statements in a try{} block will never throw an exception.

  2. The statements in a try{} block may throw several types of exception.

  3. The try{} block can not contain loops or branches.

  4. The try{} block must appear before the catch{} blocks.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

To answer this question, the user needs to know about the try-catch-finally block in exception handling.

Option A is true because not all statements in a try{} block will throw an exception, some statements may never throw an exception.

Option B is true because the statements in a try{} block may throw several types of exception.

Option C is false because the try{} block can contain loops and branches.

Option D is false because the try{} block can appear anywhere in the try-catch-finally block, as long as it appears before the catch{} and finally{} blocks.

Therefore, the answer is:

The Answer is: C. The try{} block can not contain loops or branches.

Multiple choice technology programming languages
  1. There can be several catch{} blocks in a try/catch structure.

  2. The catch{} block for a child exception class must PRECEED that of a parent execption class.

  3. The catch{} block for a child exception class must FOLLOW that of a parent execption class.

  4. If there is no catch{} block there must be a finally{} block.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In exception handling, catch blocks must be ordered from most specific to most general. A child exception class (more specific) must have its catch block BEFORE a parent exception class (more general). If a parent catch block comes first, it would catch all exceptions including child types, making child catch blocks unreachable. Therefore, the statement that child catch blocks must FOLLOW parent catch blocks is FALSE.

Multiple choice technology programming languages
  1. There must always be one, following the last catch{} block.

  2. There can be zero or one immediately after each catch{} block.

  3. There can be zero or one, following the last catch{} block.

  4. There can be any number, following the last catch{} block.

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

A try/catch structure can have either zero or one finally block, and if present, it must be placed after the last catch block. The finally block is optional but when used, there can only be one per try/catch structure. It cannot appear after each catch block individually, nor can there be multiple finally blocks. This ensures clean, predictable structure for cleanup code.

Multiple choice technology mainframe
  1. Execute this step only if any of the previous steps terminates normally

  2. Execute this step only if any of the previous steps terminates abnormally

  3. Execute next step only this step terminates abnormally

  4. Execute next step only this step terminates normally

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

COND=ONLY in JCL specifies that a step should execute only if ANY previous step in the job terminates abnormally. This is a conditional execution parameter that creates an exception handling workflow.

Multiple choice technology operating systems
  1. *This is commented

  2. //This is commented

  3. #This is commented

  4. #/This is commented

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In shell scripting, the '#' character is used to denote comments. Lines starting with '#' are ignored by the shell. Option C shows the correct comment syntax. Option D has an extra '/' character which is incorrect.

Multiple choice technology operating systems
  1. *This is commented

  2. //This is commented

  3. #This is commented

  4. #/This is commented

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

In shell scripting, the # symbol is used for comments. Any text following # on a line is ignored by the shell interpreter. The * symbol is used for file globbing (wildcards), // is used in C-style languages like Java/C++ for single-line comments, and #/ is not a standard comment syntax.

Multiple choice technology programming languages
  1. Adding a number to an int

  2. Assigning a multiplication

  3. Assigning a name to a variable

  4. Assigning a value to a variable

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

An assignment statement assigns a value to a variable using the equals operator (=). For example, int x = 5 assigns the value 5 to variable x. The right side is evaluated first, then the result is stored in the variable on the left. This is fundamental to programming.

Multiple choice technology programming languages
  1. A new type of Applet

  2. A segment of code to be run a specified amount of times

  3. A segment of code to be run infinite times

  4. A segment of code to be run once

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

A loop is a programming construct that repeatedly executes a block of code. Option B correctly describes it as code that runs a specified number of times. Option C is incorrect because most loops have termination conditions (they don't run infinitely unless specifically designed to do so). Option D is wrong because loops execute multiple times, not just once.

Multiple choice technology programming languages
  1. That there is a Boolean statement somewhere in your code

  2. That your Boolean statement will at some point be false

  3. That your Boolean statement will at some point be true

  4. All of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Ensuring a loop terminates requires that its Boolean condition will eventually become false; merely having a Boolean statement or it becoming true does not guarantee exit, so only the false‑event condition is essential.