Given the code fragment:
You want to display the value of currency as $100.00.
Which code inserted on line 1 will accomplish this?
Given the code fragment:
You want to display the value of currency as $100.00.
Which code inserted on line 1 will accomplish this?
To format a number as currency in a specific locale, the appropriate method to use is getCurrencyInstance(Locale). This method returns a currency formatter for any specified locale, which can then be used to format the number as currency. The correct code to put on line 1 is: NumberFormat formatter = NumberFormat.getCurrencyInstance(locale);
Which three initialization statements are correct? (Choose three.)
The three correct initialization statements are: 'short sh = (short)’A’;', which properly casts a character to a short type; 'float x = 1f;', which correctly initializes a float value; and 'int x = 12_34;', which correctly uses underscores in an integer literal for readability. The other options have syntactical or logical errors.
Your organization makes mlib.jar available to your cloud customers. While working on a new feature for mlib.jar, you see that the customer visible method public void enableService(String hostName, String portNumber) executes this code fragment
and you see this grant is in the security policy file:
What security vulnerability does this expose to your cloud customer's code?
The security vulnerability in question is a denial of service attack against any reachable machine. The given code uses the AccessController.doPrivileged method to create a new Socket with a specified hostname and port number. The grant in the security policy file allows the code to connect to any host using SocketPermission. This means that if a malicious user can control the hostname and port number parameters of the enableService method, they can potentially open numerous connections to any reachable host, thereby overwhelming its resources and causing a denial of service.
Given:
and
What is the result?
The given code initializes a Person object with the name 'Joe', invokes the checkPerson method on this object, and prints the object's state. Since checkPerson doesn't modify the original object reference, the name remains 'Joe'. The second part sets the object reference to null, and checkPerson creates a new Person object with the name 'Mary', although the returned new object reference is ignored, so the name remains null. Thus, the output is 'Joe' in the first print statement and 'null' in the second print statement.
Given:
What is the result?
The `Collections.unmodifiableList(list1)` method creates a read-only view of `list1`, meaning that any attempt to modify `list2` directly would result in an exception. However, modifications to `list1` are still reflected in the unmodifiable view `list2` because both lists point to the same underlying collection. Therefore, printing `list1` and `list2` will both output `[A, B, C]` since `list1` was modified by adding the element "C".