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
-
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
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.
-
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.
B
Correct answer
Explanation
In C and C++, sizeof is an operator (compile-time), not a keyword in the same category as if, while, etc. It's a built-in operator that evaluates to the size of a data type. The question's phrasing makes a technical distinction between keywords and operators.
-
Tinyint
-
Money
-
Float
-
Smallint
B
Correct answer
Explanation
In SQL Server, the modulo operator (%) cannot be used with money or smallmoney datatypes because these represent fixed-point decimal currency values rather than integers. All other listed types (tinyint, smallint, float) support the modulo operation correctly.
-
First string
-
Second string
-
Start position
-
End position
D
Correct answer
Explanation
The STUFF function in SQL Server uses four parameters: the source string (first string), start position (where deletion begins), length (number of characters to delete), and the replacement string (second string). There is no 'end position' parameter - the function uses length instead to determine how many characters to remove before inserting the replacement string.
-
Their name must begin with @
-
They are local to the batch or stored procedure where they are declared
-
They can be declared in a select statement
-
They cannot have a datatype of text or image
C
Correct answer
Explanation
Local variables in Sybase must begin with the @ symbol (option A is true). They are local to the batch or stored procedure where declared (option B is true). They cannot have text or image datatypes (option D is true). Option C is NOT true - variables cannot be declared in a SELECT statement. They must be declared using the DECLARE statement before being used in SELECT or other statements.