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
-
Geekfunc();
-
call Geekfunc();
-
function Geekfunc();
-
call function GeekFunc();
A
Correct answer
Explanation
To call or invoke a function in JavaScript, you write the function's name followed by parentheses, which contain any arguments. For example, 'Geekfunc();' successfully executes the function.
-
interface
-
throws
-
short
-
program
D
Correct answer
Explanation
Words like 'interface', 'throws', and 'short' are reserved keywords in JavaScript (or reserved for future use, especially in strict mode). 'program' is not a reserved keyword and can be freely used as a variable or function name.
-
It is necessary for your program to run correctly.
-
Helps you remember what a segment of code does.
-
Comments are used to fix your code.
-
Makes your code look pretty!
B
Correct answer
Explanation
Comments are ignored by the compiler and do not affect how a program runs or fix errors. Instead, they serve as documentation to help programmers understand and remember what specific sections of code do.
-
//I am a comment
-
class iAmaComment
-
for (I am a Comment)
-
int iAmaComment = (a < 0) ? -a : a;
A
Correct answer
Explanation
In Java, double forward slashes (//) are used to denote a single-line comment. The other options represent class declarations, loop headers, or variable assignments.
-
boolean[] running;
-
boolean running[];
-
boolean[10] running;
-
boolean running[10];
-
Runtime error
-
Logic error
-
Syntax error
-
Spelling error
C
Correct answer
Explanation
A syntax error violates the grammar rules of the Java language, which prevents the compiler from translating the source code into bytecode. Because bytecode is not generated, the program cannot be run at all.
-
int to double
-
int to String
-
double to int
-
double to String
C
Correct answer
Explanation
Converting a double to an int is a narrowing conversion because it can result in a loss of precision as the fractional part is truncated. Therefore, Java requires an explicit cast, such as (int) myDouble, to confirm this conversion.
-
if (x > 2 or < 5)
-
if (x = 4)
-
if (x < 2 && x > 5)
-
if (x)
C
Correct answer
Explanation
In Java, conditional statements inside an if-statement must evaluate to a boolean value. Option C uses the valid logical AND operator (&&) to combine two valid boolean comparisons, even though the condition itself can never be true. Other options either use invalid syntax or try to use an integer as a boolean.
A
Correct answer
Explanation
In Java, boolean variables can only hold the literal values 'true' or 'false' (all lowercase). Unlike some other languages, Java does not allow assigning integers like 1 or capitalized words like 'False' to a boolean variable.
-
boolean
-
String
-
int
-
double
B
Correct answer
Explanation
In Java, primitive data types include byte, short, int, long, float, double, char, and boolean. 'String' is a class (a reference type) rather than a primitive data type, as it represents a sequence of characters and has its own methods.
-
contain at least 3 numbers
-
USE ALL UPPER CASE LETTERS
-
give a sense of what is contained in it
-
link to a function name
C
Correct answer
Explanation
Variable names should be descriptive and meaningful so that anyone reading the code can easily understand what data the variable holds. Using arbitrary numbers or all uppercase letters is not a standard requirement, and linking to a function name is not necessary for variable declaration.
-
The CPU from completing any more cycles
-
the further execution of code
-
The internet from being accessed
-
Memory being accessed
B
Correct answer
Explanation
A runtime error occurs while a program is running, often due to unexpected inputs or operations like dividing by zero. When this happens, the program typically crashes or halts, which prevents the further execution of its code.
-
IF statement
-
For loop
-
While loop
-
List
A
Correct answer
Explanation
An 'IF' statement is a conditional control structure used in programming to execute different blocks of code based on whether a condition is true or false. Loops (like For and While) are used for repetition, and lists are data structures used to store multiple items.
-
Uses a value to return the key
-
Uses a value to return a value
-
Uses a key to return a value
-
None of the above
C
Correct answer
Explanation
The get() method in Python dictionaries is used to retrieve the value associated with a specified key. If the key does not exist in the dictionary, it returns None (or a specified default value) instead of raising an error.
-
A datatype
-
A bus
-
An error
-
A constant
A
Correct answer
Explanation
A Boolean is a fundamental data type in computer science that can only hold one of two values: True or False. It is used extensively in programming for conditional statements and logical operations.