Primitive Types
What unexpected behavior could result from accidentally using assignment '=' instead of equality '==' in an 'if' statement's conditional expression?
Using assignment results correct code path being followed each time because compiler catches mistake during compilation phase issues error message telling programmer about problem allowing prompt correction before program ever runs avoiding any potential issues related misuse operator given context here.
This causes syntax error stopping program running developers noticing fix quickly ensuring no adverse effects arise usage wrong operator circumtances described question above hence production-ready applications rarely contain kind flaw thanks stringent quality assurance processes languages themselves helping out where possible well-designed developer tools aiding detection resolution similar matters efficiently.
The assigned value always evaluates as true unless it's set to zero or boolean false leading possibly unintended branches of code executing every time regardless previous conditions met or not effectively bypassing intended logical flow checks altogether potentially introducing serious bugs especially security-related ones should happen such comparison statements control access critical system parts like authentication mechanisms etceteras thus rendering safeguard ineffective granting unauthorized users entry via seemingly benign error within single line code constituting high risk overall application stability security integrity dependability trustworthiness etcetera.
Because assignment returns variable itself evaluating true except cases zero null considered falsy values therefore entire block inside conditionals gets skipped never executed even though might crucial certain functionality aspects example logging errors handling exceptions cleaning resources managing connections iterating over collections calculating results based data retrieved databases files external services web APIs others meaning essential pieces missing lead incomplete inaccurate outputs end-users stakeholders alike dissatisfaction customer complaints loss business various other negative consequences down line.
Evaluate the expression 'int y = 10 % 4'.
4
10
1
2
What does the 'x % y' return?
The integer remainder of y divided by x
The integer remainder of x divided by y
The result of x * y
The result of x / y
Given that 'a', 'b', and 'c' are all variables of type int initialized to some values, which statement correctly stores into variable 'result' one half of the sum of squares of 'a' and 'b'?
int result = ((a * a) + (b * b)) / 2;
int result = (a^2 + b^2) / 2;
int result = a * a + b * b / 2;
int result = Math.pow(aa + bb,0.5);
If we want to insert a new value into a sorted array while maintaining its order, what typical algorithm must be used?
Quick sort algorithm applied after inserting the new element at the end of the array.
Linear search followed by an arbitrary swap or replacement action.
Sorting algorithm with insertion technique.
Binary search algorithm without modifications to the array.
Which algorithmic approach would likely be most efficient for finding an item in a balanced binary search tree?
Bubble sort then linear search.
Linear search.
Selection sort then binary search.
Binary search.
What will be the output of the following code if the integer value 0 is passed to it?
java
try {
System.out.println(10 / a);
} catch (ArithmeticException e) {
System.out.println("Error");
}
An exception is thrown but not caught
10
undefined
Error

How are we doing?
Give us your feedback and let us know how we can improve
In Java, what is the effect of following code segment on variables a
and b
? a = 10; b = a++; a = --b;
Variable a
ends up with value 11, and variable b
has the value 10.
Both variables end up with the value of 10.
Variable a
ends up with value 10, and variable b
has the value 9.
Variable a
ends up with value 9, and variable b
has the value 10.
When refactoring code, what is a primary reason for moving a block of code into its own method?
To ensure that all loops within the original block run infinitely for constant checking.
Moving blocks into their own methods prevents other methods from being executed.
It forces all variables within the original block to become global variables.
To improve readability by reducing complexity within a single method body.
Which for-loop declaration correctly traverses an integer array named 'numbers' from its end to its beginning?
for(int i = numbers.length - 1; i >=0; i--)
for(inti=numbers.lengh-1;i< numbers .length;i-- )
for(int i=0 ;i <numbers.length;i++ )
for(int i = numbers.length; i >0; i++)