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. Integer

  2. Byte

  3. String

  4. BigInteger

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

CSRF tokens are typically generated as random strings that are included in forms or requests and validated on the server. String is the standard return type for token generation methods because tokens need to be transportable in HTTP headers, form fields, or URLs. Numeric types would not serve this purpose.

Multiple choice technology security
  1. java.lang.String sign(java.lang.String data, java.lang.String key) throws EncryptionException

  2. java.lang.String sign(java.lang.String data, java.lang.String key)

  3. java.lang.String sign(java.lang.String data)

  4. java.lang.String sign(java.lang.String data) throws SecurityException

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

The sign() method takes only the data parameter and throws SecurityException because signing operations are critical security operations that can fail for various reasons (invalid key format, cryptographic errors, etc.). Unlike method A which incorrectly requires a key parameter, the signature method implies the key is managed internally. Option C is incorrect because signing can fail and should signal errors.

Multiple choice technology security
  1. java.lang.String seal(java.lang.String data,long timestamp) throws SecurityException

  2. java.lang.String seal(java.lang.String data,long timestamp) throws EncryptionException

  3. java.lang.String seal(java.lang.String data)

  4. java.lang.String seal(java.lang.String data) throws EncryptionException

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

The seal() method signature includes both the data and timestamp parameters, throwing SecurityException because cryptographic sealing operations can fail. The timestamp is essential for implementing expiration, as described in the seal() functionality. Option B incorrectly specifies EncryptionException - security API methods throw SecurityException to signal security-related failures.

Multiple choice technology security
  1. String safeURIToDisplay= "/admin/findUser.do?name=" + TCSSAPI.encoder().encodeForJavaScript(request.getParameter( "dangerousInput"));

  2. String safeURIToDisplay = TCSSAPI.encoder().encodeForURL( "/admin/findUser.do?name=" + request.getParameter( "dangerousInput" ) );

  3. String safeURIToDisplay= "/admin/findUser.do?name=" + com.tcs.sapi.io.ValidationUtil.encodeForURL(request.getParameter( "dangerousInput"));

  4. None of the above

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

When encoding user input for URLs, you must encode only the parameter value, not the entire URL string. encodeForURL applied to the whole URL (option B) would break the URL structure. encodeForJavaScript (option A) is for JavaScript context, not URLs. Option C correctly encodes only the dangerous user input portion before concatenating it with the safe URL structure.

Multiple choice technology security
  1. Validation Exception

  2. SecurityException

  3. Encoding Exception

  4. Encryption Exception

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

SecurityException is the most common exception thrown by validation methods in the security API because it serves as the base class for security-related failures. When validation fails due to security violations (invalid input, malicious patterns, policy violations), the API throws SecurityException or its subclasses. Validation, Encoding, and Encryption exceptions are not standard exception types in this API.

Multiple choice technology security
  1. SecurityException

  2. EnterpriseException

  3. EnterpriseSecurityException

  4. None of the above

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

EnterpriseSecurityException is the base class for all security-related exceptions in the TCS security API. It provides a common ancestor for specific security exceptions like authorization failures, validation errors, and authentication issues. SecurityException alone might not capture the enterprise context, and EnterpriseException is too broad for security-specific failures.

Multiple choice technology security
  1. isValidDirectory( java.lang.String context, java.lang.String input)

  2. isValidDirectory( java.lang.String context, java.lang.String input) and isValidFileName(java.lang.String context, java.lang.String input)

  3. isSafeDirectoryPath(java.lang.String context, java.lang.String input,boolean allowNull) and isSafeFileName(java.lang.String context, java.lang.String input,boolean allowNull)

  4. ValidateDirectoryPath(java.lang.String context, java.lang.String input,boolean allowNull)

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

To prevent Path Traversal attacks, TCS SAPI provides isSafeDirectoryPath() and isSafeFileName() which validate that paths don't contain dangerous patterns like '../' or absolute paths. These methods check if the input is safe for the given context before allowing file system access. Path traversal attacks attempt to access files outside the intended directory, so validating both directory paths and filenames is essential defense.

Multiple choice technology security
  1. Because the validation settings are hard coded.

  2. Susceptible to bypass using various forms of character encoding

  3. Because it's difficult to implement a black list filter that also takes into account data sent using the POST method

  4. Because it is typically implemented using regular expressions to match known good data patterns

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

Blacklist validation is weak because attackers can bypass it using various character encoding techniques: URL encoding, Unicode encoding, hex encoding, double-encoding, mixed encoding, and case variation. It's impossible to enumerate every possible malicious pattern. Options A and C are incorrect - the issue isn't about hard-coding or POST methods. Option D describes whitelist validation, not blacklist.

Multiple choice technology web technology
  1. Hashtable can have null value

  2. HashMap can have null value

  3. Hashtable is unsynchronized

  4. HashMap is synchronized

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

HashMap allows null keys and null values, whereas Hashtable does not permit either. Hashtable is synchronized (thread-safe) while HashMap is unsynchronized, making HashMap faster for non-concurrent use. The key distinction is HashMap's null support and Hashtable's legacy synchronized design.

Multiple choice technology web technology
  1. a.java.lang.Cloneable

  2. b.java.util.Collection

  3. c. java.io.Reader

  4. d. java.lang.Runnable

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

Cloneable is a marker interface - it has no methods and serves only to flag that an object can be cloned. Collection, Reader, and Runnable all declare methods. Marker interfaces like Cloneable, Serializable, and Remote are used to signal special JVM treatment rather than define behavior contracts.

Multiple choice technology testing
  1. GetVisibleText

  2. GetROProperty

  3. SetROProperty

  4. GetTOProperty

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

GetROProperty (Get Runtime Object Property) retrieves the current actual property value of objects from the application during runtime. GetTOProperty gets test object properties (descriptive), while GetVisibleText retrieves visible text content.

Multiple choice technology web technology
  1. By using sizeof operator

  2. By calling malloc method

  3. By calling getObjectSize method of Object

  4. None

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

Java has no sizeof operator or built-in way to get object size at runtime. The malloc method doesn't exist in Java (memory management is automatic), and Object class has no getObjectSize method. Object size is implementation-dependent and not directly accessible.

Multiple choice technology programming languages
  1. You can call a method on null: x.m() will not throw an error when x is null and m is a static method.

  2. null instanceof Object returns true

  3. You can pass null as the literal argument to a constructor of an anonymous inner class. e.g., new SomeClass(null) { }

  4. None of above

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

When you call a static method on a null reference (x.m() where x is null and m is static), Java doesn't throw NullPointerException because static methods are bound to the class, not the instance. The other options are false: null instanceof Object is false, and passing null to anonymous inner class constructor is generally problematic.