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
  1. 0

  2. NULL

  3. Depends on the scale and precision of the datatype.

  4. Without initialization, a variable cannot be used in the executable section of the block.

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

In PL/SQL, any scalar variable (NUMBER, VARCHAR2, DATE, etc.) that is declared but not initialized automatically gets NULL as its initial value. Option A is incorrect because 0 would need explicit initialization. Option C is wrong because NULL behavior is consistent across scale/precision. Option D is false because uninitialized variables can be used - they'll just be NULL until assigned.

Multiple choice
  1. True

  2. False

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

REF cursors in PL/SQL are cursor variables that can be passed between procedures and functions. Unlike static cursors, REF cursors are dynamic and can be opened for different queries at runtime and shared across program units.

Multiple choice
  1. Clicking Step Over to step over the execution of the subprogram

  2. Opening the Stack panel, selecting the previous stack frame, and clicking Go

  3. Clicking Step Out to resume stepping through code after the subprogram is called

  4. HE cannot do this in the same debug session. He should click Stop, set a breakpoint immediately after the subprogram code is called, and run the form in debug mode again

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

Step Over executes the entire subprogram without stepping through its internal lines, then returns control to the line immediately after the subprogram call. This is exactly what SMITH needs when he realizes the error is in code after the subprogram, not within it.

Multiple choice
  1. catch(X x) can catch subclasses of X where X is a subclass of Exception.

  2. The Error class is a RuntimeException.

  3. Any statement that can throw an Error must be enclosed in a try block.

  4. Any statement that can throw an Exception must be enclosed in a try block.

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

Option A is correct. If the class specified in the catch clause does have subclasses, any exception object that subclasses the specified class will be caught as well. Option B is wrong. The error class is a subclass of Throwable and not RuntimeException. Option C is wrong. You do not catch this class of error. Option D is wrong. An exception can be thrown to the next method higher up the call stack.

Multiple choice
  1. It is used to start a session.

  2. It is used to destroy the session.

  3. It is used to store a session variable.

  4. Both (1) and (3)

  5. None of the above

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

Yes, $_SESSION variable is used to store or retrieve the session variable.

Multiple choice
  1. A try statement must have at least one corresponding catch block.

  2. Multiple catch statements can catch the same class of exception more than once.

  3. An Error that might be thrown in a method must be declared as thrown by that method, or be handled within that method.

  4. Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block will always start to execute.

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

A is wrong. A try statement can exist without catch, but it must have a finallystatement. B is wrong. A try statement executes a block. If a value is thrown and the try statement has one or more catch clauses that can catch it, then control will be transferred to the first such catch clause. If that catch block completes normally, then the try statement completes normally. C is wrong. Exceptions of type Error and RuntimeException do not have to be caught, only checked exceptions (java.lang.Exception) have to be caught. However, speaking of Exceptions, Exceptions do not have to be handled in the same method as the throw statement. They can be passed to another method. If you put a finally block after a try and its associated catch blocks, then once execution enters the try block, the code in that finally block will definitely be executed except in the following circumstances: An exception arising in the finally block itself. The death of the thread. The use of System.exit() Turning off the power to the CPU. I suppose the last three could be classified as VM shutdown.

Multiple choice
  1. 2, 4

  2. 3, 5

  3. 4, 5

  4. 1, 2

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

(1) causes two compiler errors ( '[' expected and illegal start of expression) because the wrong type of bracket is used, ( ) instead of [ ]. The following is the correct syntax:float[ ] f = new float[3]; (2) causes a compiler error ( '{' expected ) because the array constructor does not specify the number of elements in the array. The following is the correct syntax: float f2[ ] = new float[3]; (3), (4), and (5) compile without error.

Multiple choice
  1. In an assert statement, the expression after the colon ( : ) can be any Java expression.

  2. If a switch block has no default, adding an assert default is considered appropriate.

  3. In an assert statement, if the expression after the colon ( : ) does not have a value, the assert's error message will be empty.

  4. It is appropriate to handle assertion failures using a catch clause.

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

Adding an assertion statement to a switch statement that previously had no default case is considered an excellent use of the assert mechanism. Option A is incorrect because only Java expressions that return a value can be used. For instance, a method that returns void is illegal. Option C is incorrect because the expression after the colon must have a value. Option D is incorrect because assertions throw errors and not exceptions, and assertion errors do cause program termination and should not be handled.

Multiple choice
  1. boolean

  2. void

  3. public

  4. Button

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

In Java, 'public' is an access modifier (controls visibility), not a return type. Return types specify what data type a method returns: void (returns nothing), boolean (returns true/false), or any class type like Button. Access modifiers like public, private, protected are separate concepts that specify who can access the method, not what it returns.

Multiple choice
  1. The default char data type is a space( ' ' ) character.

  2. The default integer data type is 'int' and real data type is 'float'

  3. The default integer data type is 'long' and real data type is 'float'

  4. The default integer data type is 'int' and real data type is 'double'

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

Java has default types for numeric literals. Integer literals (like 42) are int by default. Floating-point literals (like 3.14) are double by default. Option D correctly states both defaults.