Language Enhancements Flashcards
When initialize variable from primitive type does new object is used?
No
Using String in switch statement uses equals method to compare Strings
Yes
The integral types byte short int long can be expressed using the binary number system…
Yes
(byte)0b00100001
Using binary literals 0b or 0B is the same
Yes
We can use any number of underscores _ anywhere between digits in numerical literals
Yes
We can place underscore in adjacent to the decimal point literal
No 3.14_5555 is invalid
We can place underscore character prior to F or L suffix
No
int v = _90; is valid…
No
Which classes can be used as part of try with resources block…
Those that implement AutoClosable interface
The compiler can check the exact type of exception can be thrown and catch it in general Exception but declare it in the throws clause as specific types…
Yes
Any object that implements …, which includes all objects which implement java.io.Closeable can be used as a resource.
java.lang.AutoCloseable
The class BufferedReader, in Java SE 7 and later, implements the interface …
java.lang.AutoCloseable
Using try with resources if an exception is thrown from both try and finally blocks the exception from try is thrown and the exception from finally is suppressed the opposite of prior to java 7
Yes
Note that the close methods of resources are called in …
the opposite order of their creation.
Note: A try-with-resources statement can have catch and finally blocks just like an ordinary try statement. In a try-with-resources statement, any catch or finally block is run after the resources declared have been closed.
Yes
The following are the methods and constructors in Throwable that support chained exceptions….
Throwable getCause()
Throwable initCause(Throwable)
Throwable(String, Throwable)
Throwable(Throwable)
Note that it is a common mistake to forget the diamond operator
< > in the initialization expression, as in
Pair worldCup = new Pair (2010, “South Africa”); shows the compiler…
warning when you forget to use the diamond syntax.
Compiler warning when you forget to use diamond syntax…
Yes
subtyping does not work for generic parameters…
Yes
type parameters for generics have a limitation: generic type parameters should match exactly for assignments. to overcome this subtyping problem, you can use wildcard types…
Yes
You cannot instantiate a generic type using new operator. For example, assuming mem is a field, the following statement will result in a compiler error: T mem = new T(); // wrong usage - compiler error
Yes
You can declare non-static fields of type T, but not of static fields of type T. For example, class X { T instanceMem; // okay static T statMem; // wrong usage - compiler error
Yes
It is not possible to have generic exception classes; as a result, the following will not compile: class GenericException extends Throwable { } // wrong usage - compiler error
Yes
To use collections like HashSet, you must override…
the hashCode() and equals() methods correctly.