Computer Knowledge

Java Core Classes and Threads

1,935 Questions

Java core classes and threads form the foundation of object oriented programming and are crucial for IT officer and programming exams. This includes concepts like string mutability, collections, and multithreading. Solve these questions to test your practical coding and theoretical knowledge.

String and StringBuffer classesThread execution methodsJava collections frameworkCharacter streams input outputVariable serialization rules

Java Core Classes and Threads Questions

Multiple choice technology security
  1. Cross Site Scripting

  2. SQL Injection

  3. Improper Resource Release

  4. Option 1 AND Option 2

  5. Option 1 AND Option 2 AND Option 3

  6. Option 2 AND Option 3

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

This code has SQL injection vulnerability (user inputs concatenated directly into SQL statement on the 'INSERT' line). It also has XSS potential because unvalidated user input flows to output. Resources (con, stmt) may leak if exceptions occur before close() - only in catch block, no finally. Thus all three vulnerabilities are present.

Multiple choice technology security
  1. Request Redirection is vulnerable and not a good practice

  2. Exception is not logged

  3. Input parameter “language” is not validated

  4. Option 1 AND Option 2

  5. Option 1 AND Option 3

  6. Option 2 AND Option 3

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

The code is vulnerable because it uses an unvalidated input parameter ('language') directly in a 'sendRedirect' call, which can lead to Open Redirection attacks. Additionally, the exception is caught but not logged, making debugging and security auditing impossible.

Multiple choice technology security
  1. Line 5

  2. Line 4

  3. Line 11

  4. Line 18

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

Line 18 logs the username and password values when login fails. While proper parameterized queries prevent SQL injection, logging credentials in plaintext is an information leakage vulnerability - logs can be accessed by administrators or attackers who compromise the system. The code structure itself (lines 4-6) correctly uses prepared statements and is not vulnerable.

Multiple choice technology security
  1. Race Condition

  2. Command Injection

  3. Denial of Service

  4. Cross Site Request Forgery

  5. HTML Injection

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

The code directly concatenates user-controlled input (the path parameter) into a system command without validation or sanitization. Attackers can inject malicious commands through the path parameter to execute arbitrary system commands on the server.

Multiple choice technology security
  1. Line # 4

  2. Line # 13 & 20

  3. Line # 7 & 8

  4. None of the above

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

Lines 7 and 8 contain hardcoded database credentials ('admin'/'admin') and use an outdated, insecure JDBC-ODBC bridge driver, presenting a significant security vulnerability.

Multiple choice technology security
  1. Code is vulnerable as Resource is not released in the “finally” block

  2. Code is vulnerable as Resource is not released at all

  3. Code has no vulnerability

  4. Option 1 AND Option 2

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

If an exception occurs before close() calls, resources leak. Proper Java resource management requires finally blocks or try-with-resources to guarantee cleanup regardless of exceptions.

Multiple choice technology security
  1. True

  2. False

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

If an exception occurs during transaction, closeConnection() is never called, causing resource leaks. Repeated failures exhaust connection pools, creating Denial of Service.

Multiple choice technology security
  1. 1 AND 4

  2. 1 AND 2

  3. 1 AND 2 AND 3

  4. 1 AND 2 AND 3 AND 4

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

All data originating from the client side—including parameters, query strings, cookies, and headers—can be easily manipulated by an attacker and must be thoroughly validated before use.

Multiple choice technology security
  1. White list validation

  2. Blacklist validation

  3. Mix validation

  4. No validation

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

This is whitelist validation because it explicitly defines allowed characters (A-Z, a-z) using the pattern [^A-z] and rejects anything that doesn't match. Whitelist validation is more secure because it only permits known good characters, rejecting everything else as the code does with 'Invalid Input'.

Multiple choice technology security
  1. Blacklist validation

  2. Whilelist validation

  3. Hibrid validation

  4. No validation

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

This is blacklist validation because it explicitly removes specific dangerous characters (<, >, {, }, \, [, ], ;, &) from the input. Blacklist validation attempts to filter out known bad patterns but is less secure than whitelist validation because attackers can use encoding or alternative characters not in the blacklist.

Multiple choice technology programming languages
  1. int bMethod(int i) throws IOException{...}

  2. protected int bMethod(short s) throws FileNotFoundException{...}

  3. private String aMethod(byte b,short s) throws Exception{...}

  4. char bMethod(String s) throws RuntimeException{...}

  5. int bMethod(short sh){...}

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

Overloading requires a change in the method's parameter list. Changing only the return type or exceptions does not overload a method. Option 514452 changes the parameter from short to int, and option 514455 changes it to String, making both valid overloads.

Multiple choice technology programming languages
  1. int aMethod(int i) throws IOException{...}

  2. protected int aMethod(int i) throws FileNotFoundException{...}

  3. public int aMethod(int i) throws Exception{...}

  4. public int aMethod(byte i) throws IOException{...}

  5. protected int aMethod(int i) throws IOException,FileNotFoundException{...}

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

An overriding method can declare narrower or fewer checked exceptions than the overridden method, or none at all. It can also increase visibility (e.g., from protected to public). Thus, throwing FileNotFoundException (a subclass of IOException) or keeping the original signature are both valid.

Multiple choice technology web technology
  1. PsChainedException

  2. PsPageFlowException

  3. PsJspException

  4. PsServletException

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

PS (Portal Server) utilizes PsChainedException and PsServletException to wrap and handle exceptions within its web tier. PsPageFlowException and PsJspException are not standard exception classes provided by the PS framework.