java_workbook_Vignesh
java_workbook_Vignesh
1CR23MC118
ACROSS
3. Override
Clue: I am going to change your implementation
5. ParseInt
Clue: Converts string to int
7. Interface
Clue: Create an annotation
8. Autoboxing
Clue: Converts primitive type to wrapper
9. Target
Clue: I specify whom an annotation is meant for
10. Ordinal
Clue: A method gives positional value (used with enums)
DOWN
1. Values
Clue: Method that returns all enum constants
2. Retention
Clue: Specifies the scope of annotation
4. Deprecated
Clue: Oops I am no longer available
6. Marker
Clue: Annotation with no
elements
Story:
The message seems to be encrypted, but there’s a hint on the scroll: "Shift
Your task is to decrypt the message and find out where the treasure is
hidden.
Question:
Write a program using a String to decrypt the message and reveal the
location of the treasure. You need to shift each letter backward by 3 places
in the alphabet (e.g., 'D' becomes 'A').
Solution:
public class
TreasureHuntDecryptor { public
static void main(String[] args) {
String encryptedMessage = "Xfgntq wt tfqqmfy xj xjqqd!"; StringBuilder
decryptedMessage = new StringBuilder();
for (char c :
encryptedMessage.toCharArray()) { if
(Character.isLetter(c)) { char base =
Character.isUpperCase(c) ? 'A' : 'a';
Story:
The parrot responds by repeating what you said, but with all vowels
swapped.
Question:
Write a program using StringBuffer to swap the vowels in the given sentence
and output what the parrot says in response.
Solution:
args) {
{ char c = input.charAt(i);
result.append(swapVowel(c));
}
private static char swapVowel(char c) {
switch (c)
'e';
// Handle uppercase
return 'A';
default:
return c;
Story:
Solution:
import java.util.Arrays;
args) {
Arrays.sort(words);
sortedSentence.append(word).append(" ");
}
Puzzle 4: The Lost Map Pieces
Story:
[5, 3, 8, 1, 7]
The treasure is hidden at the location indicated by the last piece, so you
need to sort the pieces correctly.
Question:
Write a program using a List<Integer> to sort the list of pieces in ascending
order. Output the sorted list to find out which piece marks the treasure
location.
Solution:
import java.util.*;
args) {
Collections.sort(pieces);
}
Puzzle 5: The Wizard's Potion Ingredients
Story:
The wizard says, "I don’t need duplicates. Only unique ingredients will
work in the potion!"
Question:
Write a program using a Set<String> to remove duplicates from the list and
output the unique ingredients.
Solution:
import java.util.*;
Story:
You’ve discovered a pirate’s stash of treasure, but all the gold coins are
mixed up in different bags. You need to sort the coins by their value to
determine which bag contains the highest value. Each bag contains a list
of coins, represented by a List<Integer>.
[100, 50, 200, 150] [300, 100, 50] [200, 500, 50]
Question:
Write a program using List<List<Integer>> to sort the coins in each bag in
ascending order and print out the sorted bags of coins.
Solution:
import java.util.*;
Collections.sort(coinBags.get(i));
}
Story:
You are an archaeologist who has found several artifacts from different
time periods. These artifacts are stored in a collection, but they need to be
classified into two categories: ancient and modern.
The museum curator tells you: "Please separate the artifacts into two
lists—one for ancient artifacts and one for modern artifacts."
Question:
Write a program using two List<String> to classify the artifacts into ancient
and modern categories. Output the two separate lists.
Solution:
import java.util.*;
"Modern Sculpture",
"Ancient Sword",
"Modern Painting",
"Ancient Shield"
);
item : artifacts) { if
(item.startsWith("Ancient")) {
ancientArtifacts.add(item); } else if
(item.startsWith("Modern")) {
modernArtifacts.add(item);
System.out.println("Ancient Artifacts:");
}
System.out.println("\nModern Artifacts:");
Story:
A teacher has a list of students and their grades, but he wants to find the
highest grade and determine which student received it. The grades are
stored in a Map<String, Integer> where the key is the student’s name, and
the value is their grade.
The teacher says, "Find out who got the highest grade in the class!"
Question:
Write a program using a Map<String, Integer> to find the student with the
highest grade and output their name and grade.
import java.util.*;
args) {
grades.put("Bob", 92);
grades.put("Charlie", 88);
grades.put("David", 91);
// Variables to track highest
int highestGrade =
Integer.MIN_VALUE;
highestGrade) { highestGrade =
entry.getValue(); topStudent =
entry.getKey();
Story:
The magician says, "I need to know how many of each color I have for my
trick!"
Question:
Write a program using a Map<String, Integer> to count the occurrences of
each marble color and output the counts.
import java.util.*;
args) {
// List of marbles
marbleCount.put(marble, marbleCount.getOrDefault(marble,
0) + 1);
marbleCount.entrySet()) {
Story:
Question:
Write a program using Set<String> to find the missing key and output its
identifier.
import java.util.*;
args) {
// Find the missing key by checking the difference between the sets
expectedKeys.removeAll(foundKeys);
3. Give the code can be used to set the length of content of body of the
response?
response.setContentLength(length);
Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/dbname",
"username", "password");
connection.createStatement().addBatch("SQL_QUERY");
connection.createStatement().executeBatch();
7. List the methods of resultset. resultSet.getString(), resultSet.getInt(),
resultSet.getDate(), resultSet.next(), resultSet.previous(), etc.
Accept-Language
3. Specifies the Client proferred Languages
ck.setMaxAge(0)
8. Set cookie age to as zero
9.
a) javax.servlet List 2 packages represent interfaces and
b) javax.servlet.http classes for servlet api
10. HttpSession Provides a way to identify a user across
more than one page request or visit to a
Web site and to store information about
that user
public String Returns a string containing servlet information
11. (description etc.)
getServletInfo()