What is the index of the first element in a Java array?
0
What will this code output:
int[] arr = {1, 2, 3};
System.out.println(arr[1]);
2
What is the value of arr[2] in int[] arr = {10, 20, 30, 40}?
30
CIA Triad stands for
Confidentiality
Integrity
Availability
This term refers to a set of instructions that a computer follows to perform a task, and it is a core concept in software development.
Programming
How do you declare an array of integers in Java?
int[] arr = new int[5];
Write a loop to print all elements of the array:
int[] arr = {1, 2, 3, 4};
int[] arr = {1, 2, 3, 4};
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
How would you change the value of the first element in an array?
array[0] = value;
A company hashes their data files in order to monitor whether information has been tampered with.
Integrity
This control structure in Java evaluates a condition and executes one block of code if true, and another block if false.
IF statement
What is the size of the array int[] arr = {5, 10, 15, 20, 25}?
5
Write the code to find the sum of elements in an array.
int[] arr = {1, 2, 3};
int[] arr = {1, 2, 3};
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
}
System.out.println(sum);
What is the result of this operation: arr[0] = arr[1] + arr[2] in int[] arr = {1, 2, 3}?
arr[0] becomes 5 (since 2 + 3 = 5).
A technology firm maintains an alternate site that is running 24/7, and operations can be moved to this location in the event of a major disaster.
Availability
This type of loop in Java will continue executing a block of code as long as a specified condition is true, often used when the number of iterations is not known in advance.
WHILE loop
What does arr[arr.length - 1] represent in an array?
last element in the array
Write a code to get the maximum element in an array.
int max = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] > max) {
max = arr[i];
}
}
What happens when you try to access an index outside the bounds of an array?
It throws an ArrayIndexOutOfBoundsException.
Employees need to have key cards in order to enter their company offices.
Confidentiality
In Java, this special method is used to initialize an object when it is created, typically setting values for the object's attributes.
Constructor
Explain how array indexing works in Java.
Array indexing in Java starts at 0, meaning the first element is accessed with index 0.
Explain how nested loops work when traversing a 2D array.
The outer loop iterates over the rows, and the inner loop iterates over the elements (columns) in each row.
Write a code to double each element in an array.
for (int i = 0; i < arr.length; i++) { arr[i] *= 2; }
A hacker launched a DDoS attack which flooded a website with unwanted traffic from a number of computers.
Availability
This concept in Java allows a method to call itself, which can be especially useful in solving problems that can be broken down into smaller, similar subproblems.
Recursion