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. This is not legal, so the program will not compile.

  2. The method throws the exception to its caller if there were no matching catch{} block.

  3. The program halts immediately.

  4. The program ignores the exception.

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

When an exception is thrown in a try block and no matching catch block exists, the exception propagates up the call stack. The method throws the exception to its caller, following Java's exception propagation mechanism. This allows higher-level methods to handle the exception or continue propagating it. The program does not halt immediately, ignore the exception, or fail to compile - this is legal Java code.

Multiple choice technology programming languages
  1. Only when an unhandled exception is thrown in a try{} block.

  2. Only when any exception is thrown in a try{} block.

  3. Always after execution has left a try{} block, no matter for what reason.

  4. Always just as a method is about to finish.

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

A finally block is ALWAYS executed after execution leaves the try block, regardless of how it exits - whether via normal completion, a caught or uncaught exception, return, break, or continue statements. This guarantee makes finally blocks ideal for cleanup code that must run under all circumstances. The finally block executes even when no exception occurs or when the exception is caught.

Multiple choice technology
  1. eval

  2. getProperty

  3. escape

  4. call

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

The escape() function in ActionScript converts a parameter to a string and encodes it in URL-encoded format. All non-alphanumeric characters (except some like * @ - _ . +) are replaced with %XX hexadecimal sequences. For example, a space becomes %20. This is essential for passing data safely in URLs.

Multiple choice technology programming languages
  1. findAllCustomers(…)

  2. removeTheCustomer(…)

  3. createCustomer(…)

  4. create()

  5. retrieveCustData(…)

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

EJB home interfaces for entity beans have strict naming conventions. Methods starting with 'create' (like createCustomer) are reserved for create methods. Methods starting with 'find' (like findAllCustomers) are reserved for finder methods. Method names like removeTheCustomer conflict with EQL reserved keywords. The method name 'create' alone is a reserved word in EJB context. Only retrieveCustData() doesn't violate these conventions.

Multiple choice technology programming languages
  1. One or more

  2. Zero or more

  3. Exactly one

  4. Zero

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

Entity bean home interfaces can have zero or more create methods. Unlike session beans which must have at least one create method, entity beans are not required to have any create methods - they can rely exclusively on finder methods to locate existing entities. When create methods are defined, there's no upper limit on how many can exist.

Multiple choice technology programming languages
  1. ObjectNotFoundException.

  2. An empty Collection will be returned.

  3. An entity would be created and a reference to that entity would be returned.

  4. EntityNotFoundException.

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

According to the EJB specification, finder methods returning a Collection must return an empty collection if no matching entities are found. ObjectNotFoundException is only thrown for single-object finder methods (like findByPrimaryKey) when a match is missing, while automatic entity creation never occurs on a failed lookup.

Multiple choice technology web technology
  1. ejbActivate()

  2. ejbStore()

  3. ejbFindByPrimaryKey()

  4. ejbPostCreate()

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

When an ejbCreate is invoked, the container must subsequently invoke the corresponding ejbPostCreate with the same parameters. This post-create method allows additional initialization after the primary key is assigned. ejbActivate() is for passivation/activation, ejbStore() is for synchronization, and ejbFindByPrimaryKey() is a finder method - none are automatically invoked after ejbCreate.

Multiple choice technology programming languages
  1. public void perform() { }

  2. public boolean perform() { }

  3. static public boolean perform() { }

  4. public void perform() throws Exception { }

  5. public boolean perform() throws Exception { }

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

The perform() method in a Perform node must be public, return void, and declare throws Exception to handle any exceptions that may occur during execution. The method needs to throw Exception rather than return boolean because the framework handles exception propagation. Static methods are not used for instance-level perform nodes.

Multiple choice technology programming languages
  1. Array Object

  2. Neither Object

  3. String Objec

  4. Both of the Objects

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

Tracing the code: after creating the array and String, assigning 'students[0] = studentName' creates a second reference to 'Peter Parker'. Setting 'studentName = null' only removes one reference. The array object is still referenced by 'students' variable, and the String object is still referenced by 'students[0]'. Neither object loses all references, so neither is eligible for garbage collection.

Multiple choice technology programming languages
  1. X is a method Signature and Y is a method Header

  2. Both X and Y is a method Header

  3. X is a method Header and Y is a method Signature

  4. Both X and Y is a method Signature

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

X is a method header because it includes modifiers (public, final), return type (String), method name (getDetails), parameters (File file, String key), and throws clause. Y is a method signature because it only includes the method name and parameter types without modifiers or return type.

Multiple choice technology programming languages
  1. HttpServletRequest

  2. HttpServletResponse

  3. ServletRequest

  4. ServletResponse

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

sendError() and sendStatus() are methods of HttpServletResponse that send HTTP error responses and status codes to the client. HttpServletRequest handles request data, while ServletRequest and ServletResponse are generic interfaces that HttpServlet extends.