Computer Knowledge

Programming Fundamentals

2,381 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. Arrays in Java are essentially objects

  2. It is not possible to assign one array to another. Individual elements of array can however be assigned.

  3. Array elements are indexed from 1 to size of array

  4. If a method tries to access an array element beyond its range, a compile warning is generated.

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

Arrays in Java are objects - they're dynamically allocated, have a length field, and inherit from Object class. Options B, C, and D are false: arrays of the same type can be assigned (reference copy), indexing starts at 0 not 1, and out-of-range access throws ArrayIndexOutOfBoundsException at runtime, not a compile warning.

Multiple choice technology programming languages
  1. Float.POSITIVE_INFINITY

  2. Double.POSITIVE_INFINITY

  3. runtime Exception

  4. None of the Above

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

In Java, Math.max(double, double) is invoked due to overload resolution converting the float argument to a double. Double.POSITIVE_INFINITY and Float.POSITIVE_INFINITY are mathematically equal, but the method returns a double type representation of positive infinity.

Multiple choice technology programming languages
  1. True

  2. False

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

Casting between numeric types (int, long, float, double, short, byte, char) is a fundamental operation in Java. This includes both widening conversions (like int to long) which are implicit, and narrowing conversions (like double to int) which require explicit casting. Primitive numeric types have well-defined conversion rules, making casting between them a common operation.

Multiple choice technology programming languages
  1. int $x
  2. int 123

  3. int _123

  4. int #dim

  5. int %percent

  6. int central_sales_region_Summer_2005_gross_sales

Reveal answer Fill a bubble to check yourself
A,C,F Correct answer
Explanation

Java identifiers can begin with a letter, underscore, or dollar sign. They cannot begin with a number, hash sign, or percent sign. Thus, $x, _123, and central_sales_region_Summer_2005_gross_sales are valid declarations, while 123, #dim, and %percent are invalid.

Multiple choice technology programming languages
  1. Compilation fails.

  2. An exception is thrown at runtime.

  3. The code executes normally and prints "bar".

  4. The code executes normally, but nothing prints.

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

This code creates an anonymous inner class implementing Runnable, then starts a Thread with it. The code compiles successfully because: 1) The anonymous inner class syntax is correct: new Runnable() { public void run() {...} } 2) The Runnable interface is properly implemented with the run() method 3) The Thread constructor accepts a Runnable 4) The start() method is called correctly on the Thread. When the thread runs, it executes the run() method, which prints 'bar' to the console.

Multiple choice technology testing
  1. the use of a variable before it has been defined

  2. memory leaks

  3. unreachable (“dead”) code

  4. array bound violations

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

Static analysis analyzes code without executing it, finding issues like unused variables, dead code, or syntax violations. Memory leaks typically occur dynamically during runtime execution, making them impossible for standard static analysis to reliably detect.

Multiple choice technology programming languages
  1. List<List<Integer>> table = new List<List<Integer>>();

  2. List<List<Integer>> table = new ArrayList<List<Integer>>();

  3. List<List<Integer>> table = new ArrayList<ArrayList<Integer>>();

  4. List<List, Integer> table = new List<List, Integer>();

  5. List<List, Integer> table = new ArrayList<List, Integer>();

  6. List<List, Integer> table = new ArrayList<ArrayList, Integer>();

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

The code needs a mutable List of Lists. Option B is correct because ArrayList> implements List> due to generic type compatibility. Option A fails because List is an interface and cannot be instantiated. Options C, E, F have incorrect generic syntax. Option D is invalid syntax. The diamond operator works because the inner type parameter is inferred.

Multiple choice technology mainframe
  1. For loop

  2. Do-While loop

  3. Method

  4. All of the above

  5. None of the above

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

The COBOL PERFORM loop with the UNTIL clause executes the paragraph at least once and then tests the condition, which is the same behavior as a do-while loop in Java or C++. A for loop typically initializes and tests before execution, and a method is a completely different construct (a subprogram, not a loop).

Multiple choice technology mainframe
  1. use a standard perform statement

  2. use an in line perform

  3. skillful use of the COBOL reserved word "AFTER"

  4. This is not possible in COBOL

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

In COBOL, specifying PERFORM WITH TEST AFTER guarantees the loop body executes at least once before testing the loop condition, acting as a post-test loop. Standard or inline PERFORM statements default to checking the condition first (TEST BEFORE), while the AFTER option is the precise mechanism to alter this evaluation timing.

Multiple choice technology mainframe
  1. True

  2. False

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

Unlike functions like COUNT(column_name), which ignore NULL values, COUNT(*) counts all rows in the target table, including those containing NULL values or duplicate values.

Multiple choice technology programming languages
  1. a) A stored procedure on the server

  2. b) A block of code in a PL/SQL library.

  3. e) A local subprogram defined within the program unit ORDERTOTAL

  4. d) A block of code in the body of the program unit ORDERTOTAL

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

A local subprogram defined within ORDERTOTAL is the most appropriate choice because the code is only needed within that specific program unit. Stored procedures (server-wide) or PL/SQL libraries (broader scope) would be excessive when the functionality has a single, specific use case.