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
-
No. You can write a program to catch just the exceptions you want.
-
No. But if a program catches one type of exception it must catch all other types as well.
-
Yes. If a program is not written to catch all exceptions it will not compile.
-
Yes. A program can not do I/O unless it catches all exceptions.
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.
B
Correct answer
Explanation
A try block must be followed by either catch blocks, a finally block, or both. It's valid to have try-finally without any catch blocks. The finally block provides optional cleanup.
-
Some of the statements in a try{} block will never throw an exception.
-
The statements in a try{} block may throw several types of exception.
-
The try{} block can not contain loops or branches.
-
The try{} block must appear before the catch{} blocks.
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.
-
There can be several catch{} blocks in a try/catch structure.
-
The catch{} block for a child exception class must PRECEED that of a parent execption class.
-
The catch{} block for a child exception class must FOLLOW that of a parent execption class.
-
If there is no catch{} block there must be a finally{} block.
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.
-
There must always be one, following the last catch{} block.
-
There can be zero or one immediately after each catch{} block.
-
There can be zero or one, following the last catch{} block.
-
There can be any number, following the last catch{} block.
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.
-
Numeric data
-
Data type
-
Char data
-
None of the Above
-
Execute this step only if any of the previous steps terminates normally
-
Execute this step only if any of the previous steps terminates abnormally
-
Execute next step only this step terminates abnormally
-
Execute next step only this step terminates normally
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.
B
Correct answer
Explanation
SSIS variables can be defined at multiple scopes: package level, container level, task level, or event handler level. They are not restricted to only the entire package scope.
-
*This is commented
-
//This is commented
-
#This is commented
-
#/This is commented
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.
-
*This is commented
-
//This is commented
-
#This is commented
-
#/This is commented
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.
-
variableName variableType;
-
variableName;
-
variableType;
-
variableType variableName;
D
Correct answer
Explanation
In most languages the correct declaration order is type first then variable name (e.g., int count;). The other formats either omit the type or reverse the order, which are syntactically invalid.
-
Adding a number to an int
-
Assigning a multiplication
-
Assigning a name to a variable
-
Assigning a value to a variable
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.
-
A new type of Applet
-
A segment of code to be run a specified amount of times
-
A segment of code to be run infinite times
-
A segment of code to be run once
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.
-
That there is a Boolean statement somewhere in your code
-
That your Boolean statement will at some point be false
-
That your Boolean statement will at some point be true
-
All of the above
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.