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
-
Array: can store primitive ArrayList: Stores object only
-
Array: fix size ArrayList: resizable
-
Array: can have multi dimensional ArrayList: can have multi dimensional
-
Array: lang ArrayList: Collection framework
A,B,D
Correct answer
Explanation
Arrays are fixed-size, built-in language structures that can store primitives directly. ArrayList is a resizable class within the Collections Framework that only stores objects, utilizing autoboxing for primitives. Additionally, arrays natively support multi-dimensional syntax, whereas ArrayList does not, and Arrays are part of Java language basics while ArrayList is in java.util.
-
incSize(int minCapacity)
-
ensureCapacity(int minCapacity)
-
incCapicity(int minCapacity)
-
All of the Above
B
Correct answer
Explanation
ArrayList uses ensureCapacity(int minCapacity) to request internal capacity expansion before adding elements. This is an optimization to avoid multiple internal array resizes. Option A's 'incSize' and option C's 'incCapicity' (misspelled) don't exist in the API.
-
Returns String
-
Returns an Array
-
Returns a shallow copy of this ArrayList instance
-
Returns Void
C
Correct answer
Explanation
The clone() method in ArrayList returns a shallow copy - the ArrayList object itself is new, but the elements are references to the same objects (not deep copies). It doesn't return a String, Array, or void.
-
Object
-
Plain text
-
xml
-
e4x
A
Correct answer
Explanation
When the class in Adobe Flex returns complex data (like XML or JSON), the default resultFormat is 'object'. This means the response is automatically parsed and converted into an ActionScript object structure. Other formats like 'xml', 'e4x', or 'text' must be explicitly specified if needed.
-
sort
-
sortOn
-
reverse
-
sortBy
B
Correct answer
Explanation
In ActionScript, sortOn() sorts an array of objects based on a specific property of each object. The sort() method sorts simple values or requires a custom function, reverse() reverses order, and sortBy() does not exist.
-
Use the property called “data” in event Object
-
Use the property called “payload” in event Object
-
Create a Custom Event and have your own public variable to hold the data to be passed to the handler
-
No way to do that.
C
Correct answer
Explanation
The standard and most flexible way to pass custom data to an event handler is to create a custom Event class with public properties to hold the data. The base Event object does not have built-in properties like 'data' or 'payload' for arbitrary data. By extending Event and adding your own properties, you can type-safely pass any data needed by the handler.
B
Correct answer
Explanation
NullPointerException is an unchecked exception in Java because it inherits from RuntimeException. Checked exceptions must be declared in a method's throws clause or handled in a try-catch block, whereas unchecked exceptions represent programming errors occurring at runtime that do not require explicit handling.
B
Correct answer
Explanation
The statement "Declarations must appear at the start of the body of a Java method" is false.
In Java, variable declarations can appear anywhere within the body of a method, as long as they are declared before they are used. This allows for more flexibility in the design of a program and allows the programmer to declare variables closer to the point of their actual use, making the code more readable and easier to maintain.
Therefore, the correct answer is:
The Answer is: B. False
-
doInit()
-
doUpdate()
-
doPageAction()
-
None of the above
-
doComplete()
-
doCancel()
-
doInit()
-
doUpdate()
C
Correct answer
Explanation
The doInit() method is the standard lifecycle method invoked when a page is first loaded or initialized in the PS Framework. doComplete() is called after successful form submission, doCancel() handles cancellation actions, and doUpdate() is for update operations during page lifecycle.
B
Correct answer
Explanation
Only one String object is created by 'new String("Cheese")'. The 'String strA;' declaration only creates a reference variable (null initially), not an object. In practice, this code would use a string literal instead, but technically only the 'new' keyword creates an object.
-
JB (jump back)
-
JA (jump above)
-
JO (jump if overflow)
-
JMP (unconditional jump)
A
Correct answer
Explanation
Standard conditional jump instructions in assembly include JA (Jump if Above), JO (Jump if Overflow), and JMP (unconditional jump). 'JB' is not a standard assembly mnemonic - the correct instruction for 'jump back' would be something like JMP with a negative offset or a loop instruction. The question asks which is NOT a jump instruction, and JB is indeed the invalid one.
-
Query length is limited in POST, not limited in GET.
-
POST is secured whereas data is been submitted as part of URL in GET (not secured).
-
By using POST method, we cannot submit the form.
-
none
B
Correct answer
Explanation
POST is more secure than GET because POST data is sent in the HTTP request body, not visible in the URL. GET appends form data to the URL, making it visible in browser history and server logs, and has length limitations (typically 2048 characters). POST can send much larger data and is the standard method for sensitive information like passwords. Option A incorrectly reverses the length limitations, and Option C is false.
-
HttpSession
-
HttpServletResponse
-
HttpServletRequest
-
none
B
Correct answer
Explanation
The HttpServletResponse interface provides the getWriter() method, which returns a PrintWriter object for sending character text data to the client. This is the standard way to write response content in servlets. HttpServletRequest (request) handles incoming data, HttpSession manages user sessions, and PrintWriter itself is the class returned, not the source of it. The leading period appears to be a typo but doesn't affect the question.
-
getAttribute()
-
getParameter()
-
getInitParameter()
-
none
A
Correct answer
Explanation
getAttribute() retrieves object-level attributes stored in the request scope. This is different from getParameter() which retrieves string form parameters from the query string or POST body, and getInitParameter() which retrieves servlet initialization parameters from web.xml. Attributes are typically set by the application using setAttribute() to share data between components, while parameters come from client requests.