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

Multiple choice chemistry chemical thermodynamics system and surroundings introduction to thermodynamics basics of thermodynamics

Which statement BEST describes why work is a path function

  1. You finish at a different place

  2. You start at a different place

  3. The amount of work varies depending on which path you take to get to the destination

  4. The amount of work is the same whichever path you take to get to the destination

  5. Work is not a path function, it is a state function

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

The statement (C) BEST describes why work is a path function.
The amount of work varies depending on which path you take to get to the destination.
State function is independent of the pah followed whereas path function is dependent on path followed.

Multiple choice chemistry chemical thermodynamics system and surroundings introduction to thermodynamics basics of thermodynamics

Work is __________ function.

  1. path

  2. state

  3. both path and state

  4. none of these

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

Work is a path function and not a state function. The amount of work done is different for different paths although the initial and final states are the same. The amount of work depends on the path connecting the initial and final states.

Multiple choice
  1. The point at which the recursion loop will stop

  2. The element of a program that can be represented recursively

  3. An error causing the recursion loop to stop

  4. A for loop

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

In recursion, the base case is the condition that terminates the recursive calls. Without it, the function would call itself indefinitely, leading to a stack overflow error.

Multiple choice
  1. execute

  2. read

  3. write

  4. nothing

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

In the standard Unix permission triplet (rwx), the 'x' character stands for execute permission.

Multiple choice
  1. True

  2. False

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

Unchecked exceptions, which are subclasses of RuntimeException, do not have to be caught or declared in a throws clause. The compiler does not force you to handle them, although you can choose to do so. Only checked exceptions must be handled using a try/catch block or declared in the method signature.

Multiple choice
  1. True

  2. False

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

A try-finally block is completely legal in Java. You do not need a catch block if you have a finally block, which is useful when you want to ensure cleanup code runs regardless of whether an exception is thrown, while letting the exception propagate up the call stack.

Multiple choice
  1. int 5 = x;

  2. 5 = x int;

  3. int x = 5;

  4. x = 5 int;

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

In Java, variable declaration and assignment must follow the syntax: data type, followed by the variable name, the assignment operator (=), and finally the value. Therefore, 'int x = 5;' is the only syntactically correct option.

Multiple choice
  1. Geekfunc();

  2. call Geekfunc();

  3. function Geekfunc();

  4. call function GeekFunc();

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. interface

  2. throws

  3. short

  4. program

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. It is necessary for your program to run correctly.

  2. Helps you remember what a segment of code does.

  3. Comments are used to fix your code.

  4. Makes your code look pretty!

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. //I am a comment

  2. class iAmaComment

  3. for (I am a Comment)

  4. int iAmaComment = (a < 0) ? -a : a;

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. Runtime error

  2. Logic error

  3. Syntax error

  4. Spelling error

Reveal answer Fill a bubble to check yourself
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.

Multiple choice
  1. int to double

  2. int to String

  3. double to int

  4. double to String

Reveal answer Fill a bubble to check yourself
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.