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 programming languages
  1. The before() method will print 1 2

  2. The before() method will print 1 2 3

  3. The before() method will print three numbers, but the order cannot be determined

  4. The before() method will not compile

  5. The before() method will throw exception at runtime

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

The code will throw a ClassCastException at runtime. A TreeSet is genericized to hold objects of the same type, but raw types (without generics) allow mixing. When the code adds '2' (String), then 3 (auto-boxed to Integer), then '1' (String), the TreeSet tries to sort them using natural ordering. When it compares the Integer 3 with String '1', it cannot cast Integer to String, causing a ClassCastException.

Multiple choice technology testing
  1. Wait – makes a wait for the specified seconds with optional milliseconds

  2. Wait – makes a wait for the specified seconds only

  3. Wait – makes a wait for the specified seconds with mandatory milliseconds

  4. None of the statements are true

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

The Wait method in QTP/UFT (inherited from VBScript) accepts seconds as a required parameter and milliseconds as an optional parameter. The syntax is Wait(seconds, milliseconds), where milliseconds can be omitted. Option B incorrectly states milliseconds are not supported, while option C incorrectly states they are mandatory.

Multiple choice technology testing
  1. GetTOProperty

  2. SetTOProperty

  3. GetROProperty

  4. None

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

GetROProperty (Run-Time Object Property) is used to retrieve the actual runtime value of an object's property, such as user input or dynamically generated values. GetTOProperty retrieves test object properties (descriptive properties), while SetTOProperty modifies test object properties but doesn't affect runtime objects.

Multiple choice technology packaged enterprise solutions
  1. pyPropertyStatus

  2. pxMethodStatus

  3. pxPropertyStatus

  4. pyMethodStatus

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

In Pega, most activity methods, including Property-Remove, update the system property pxMethodStatus to indicate the success or failure status of the method execution. Property-specific or developer-defined properties like pyPropertyStatus are not automatically updated by system methods.

Multiple choice technology programming languages
  1. 1 Object

  2. 2 Objects

  3. 3 Objects

  4. 4 Objects

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

The statement String s = 'abc' creates one object in the String Constant Pool. String s1 = new String('def') creates two objects: one in the String Constant Pool and one in the heap. In total, three objects are created, making '3 Objects' the correct answer.

Multiple choice technology testing
  1. show(long a,byte b){ }

  2. show(byte b, long a){ }

  3. runtime exception

  4. none of the above

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

In Java, calling show(10, 10) passing two integer literals (int) requires implicit promotions. Both show(long, byte) and show(byte, long) would require one promotion to long and one demotion/narrowing to byte, which is invalid without casting. Hence, it causes a compile-time ambiguity or error, matching none of the above options.

Multiple choice technology programming languages
  1. True

  2. False

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

To solve this question, the user needs to know the basic concept of thread safety in Java and how it applies to local variables in methods like service(), doPost() and doGet().

The answer to this question is:

A. True

Explanation:

Local variables declared within a method are thread-safe because they are confined to the method and are not shared between threads. Each thread, when executing the method, will have its own copy of the local variables declared within the method. As a result, other threads cannot modify the values of these local variables, ensuring thread safety.

Therefore, the correct answer is option A, true.

Multiple choice technology programming languages
  1. getParameterValue()

  2. getParameters()

  3. getParamValues()

  4. getParameterValues()

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

The getParameterValues() method of the ServletRequest interface returns an array of String objects containing all of the values that the given request parameter has, or null if the parameter does not exist. The other methods do not exist or return single values.

Multiple choice technology programming languages
  1. It is declared in the local home interface of a stateful session bean.

  2. It is declared in the local home interface of a stateless session bean.

  3. It is declared in the remote home interface of a stateful session bean.

  4. It is declared in the remote home interface of a stateless session bean.

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

The method signature shows RemoteException in the throws clause, which is only present in remote interfaces (local interfaces don't throw RemoteException). The create method with parameters can be used by stateful session beans to initialize state during creation, whereas stateless session beans typically have no-arg create methods.

Multiple choice technology programming languages
  1. True

  2. False

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

Java has both static and dynamic dispatch. Static dispatch occurs for private, static, and final methods - these are resolved at compile time based on the declared type. Dynamic dispatch (virtual method invocation) occurs for overridden instance methods, resolved at runtime based on the actual object type.

Multiple choice technology security
  1. Identifying all possible erroneous inputs and managing how the application responds to them

  2. During application execution, if some special conditions are met, then a specific subroutine 'exception handler' is called

  3. Commercial runtime environments have tools that record debugging information from memory at the time of exception to provide 'root-cause' analysis information later.

  4. All of the above

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

To answer this question, the user needs to have knowledge about exception handling in programming.

Option A is incorrect because identifying all possible erroneous inputs and managing how the application responds to them is a part of input validation. It is not the same as exception handling.

Option B is partially correct. During application execution, if some special conditions are met, then a specific subroutine 'exception handler' is called. Exception handling involves detecting errors that occur during the execution of a program and taking appropriate action to handle them. The "specific subroutine" is the exception handler which is executed when an exception is thrown.

Option C is also partially correct. Commercial runtime environments have tools that record debugging information from memory at the time of exception to provide 'root-cause' analysis information later. This tool is essential to debug errors and improve the quality of the software.

Option D is correct because all the options A, B, and C are correct explanations of exception handling.

Therefore, the answer is: D. All of the above.

Multiple choice technology security
  1. Sql Injection attack

  2. Denial of Service attack

  3. CSRF attack

  4. None of these

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

The readLine() method in Java reads input until a line delimiter is found. If an attacker sends a continuous stream of data without newlines, it can exhaust heap space and trigger an OutOfMemoryError, causing a denial of service.

Multiple choice technology security
  1. It is returning a value in finally block

  2. It is catching Exception

  3. Both a & b

  4. Nothing is wrong

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

Returning in a finally block is problematic because it discards any exception that was thrown in the try/catch blocks and overrides return values from both try and catch. This can hide security-relevant exceptions. Catching the generic Exception instead of specific exceptions is also a security anti-pattern that can mask error conditions.

Multiple choice technology security
  1. 1

  2. 1 and 2

  3. 1,2 and 3

  4. 1,2,3 and 4

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

All four methods (getParameter, getQueryString, getCookies, getHeaders) return data from the HTTP request, which comes from an external source (the client/browser). This data is attacker-controlled and must be validated before use to prevent injection attacks, header manipulation, or other security issues. getParameter and getQueryString are obvious, but cookies and headers are also user-supplied and can be malicious.

Multiple choice technology security
  1. Line 9

  2. Line 5

  3. Line 7

  4. Line 1

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

Line 1 sets bIsAdmin = true before any authentication occurs. If an exception is thrown in function() at line 4, execution jumps to the catch block and line 5 (the actual admin check) never executes. The exception is logged but bIsAdmin remains true, allowing unauthorized admin access. This is a vulnerable default-privileged design - sensitive flags should default to false.