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
-
PARA A
-
PARA B
-
PARA C
-
PARA D
B
Correct answer
Explanation
The COBOL GOTO statement with DEPENDING ON uses 1-based indexing: GOTO A,B,C,D DEPENDING ON X transfers control to the first label when X=1, second label when X=2, third when X=3, fourth when X=4. When X=2, control transfers to PARA B. This is a computed GOTO based on the ordinal position of the labels.
-
catch,finally
-
finally
-
catch
-
catch,catch,finally
A,B,D
Correct answer
Explanation
In Java, a try block must be followed by either a catch block, a finally block, or both. The options correctly identify valid combinations like try-catch-finally, try-finally, and multiple catches. However, the option "catch" is marked false when a single catch block is also syntactically valid in Java. Since 'catch' is marked false, the stored answers are partially inconsistent, but try-catch-finally and try-finally are indeed correct.
-
catch,finally
-
finally
-
catch
-
catch,catch,finally
A,B,D
Correct answer
Explanation
In Java, a try block must be followed by either a catch block, a finally block, or both. Option A shows catch+finally which is valid. Option B shows finally only which is also valid. Option D shows multiple catch blocks followed by finally, which is valid syntax for handling different exception types sequentially.
-
when no exception occurs
-
when exception occurs
-
Based on the exception
-
Never
A,B
Correct answer
Explanation
The finally block in Java is designed to execute code regardless of whether an exception is thrown or caught, ensuring cleanup operations run. It does not depend on the exception type and is not skipped.
A
Correct answer
Explanation
JavaScript allows return statements in finally blocks. When a finally block contains a return statement, it will override any return value from the try or catch blocks. This is generally considered a bad practice as it can suppress exceptions and make debugging difficult, but it is syntactically valid.
B
Correct answer
Explanation
The CTS (Common Type System) defines how types are declared and used in the .NET framework. Pointers are NOT part of the CTS - they are part of 'unsafe' code in C# and operate outside the normal type system safety guarantees. Pointers are a non-CLS compliant feature.
A
Correct answer
Explanation
Exceptions can indeed be rethrown in Java and other languages. After catching an exception, code can explicitly rethrow the same exception (or wrap it in a new exception) using 'throw;' or 'throw ex;'. This is commonly used for adding context, logging, or handling exceptions at multiple levels of the call stack.
A
Correct answer
Explanation
A double can be cast to a byte in Java using explicit casting, but this will result in data loss since a byte is only 8 bits while a double is 64 bits. The cast truncates the decimal part and may overflow if the value is outside byte range (-128 to 127).
B
Correct answer
Explanation
When you add a double value to a String in Java, the double is automatically converted to a String representation and concatenated with the original String, resulting in a new String. This is string concatenation, not arithmetic addition.
B
Correct answer
Explanation
Once an object is garbage collected, it becomes permanently unreachable. An object cannot be resurrected or made reachable again after garbage collection. If you need to reclaim resources, use finalization or try-with-resources instead.
B
Correct answer
Explanation
In Java, assigning an int to a byte requires an explicit cast because it is a narrowing primitive conversion that can lead to information loss. Without a cast, this code results in a compilation error.
-
ALPHABETIC
-
ALPHANUMERIC
-
NUMERIC
-
BOOLEAN
D
Correct answer
Explanation
BOOLEAN is not a standard COBOL datatype. Traditional COBOL uses PICTURE clauses to define data formats like ALPHABETIC (A), ALPHANUMERIC (X), and NUMERIC (9 or S9). While modern COBOL implementations may support boolean-like conditions, BOOLEAN as an explicit datatype is not part of standard COBOL. The question asks which datatype is NOT used in COBOL - BOOLEAN is the correct answer.
B
Correct answer
Explanation
WHILE is not a keyword in standard COBOL. COBOL uses PERFORM...UNTIL for looping constructs, not WHILE. For example, 'PERFORM UNTIL condition' or 'PERFORM varying... UNTIL condition'. The WHILE keyword exists in languages like C, Java, and Python, but not in traditional COBOL. False is the correct answer.
B
Correct answer
Explanation
In Java, you cannot directly cast a wrapper Byte object reference to a primitive double or a Double object reference because they belong to different class hierarchies. Although auto-unboxing allows implicit conversion during assignments, an explicit object reference cast is invalid and will fail compilation.
-
Active
-
Passive
-
Can be Active or Passive
-
None
C
Correct answer
Explanation
A Mapplet in Informatica can be either Active or Passive depending on its transformations. An Active Mapplet contains at least one Active transformation (like Aggregator, Filter, Joiner) that changes the number of rows passing through it. A Passive Mapplet contains only Passive transformations (like Expression) that maintain the same row count. The classification depends entirely on the transformations used within the mapplet.