Test 2 Flashcards

1
Q

ConcurrentMap

A

It is a Map providing atomic versions of putIfAbsent, remove, and replace methods. dont provide any additional method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When interfaces are involved, more than one method declaration may be overridden by a single overriding declaration. The overriding declaration must have a throws clause that is compatible with ALL the overridden declarations. the most childish

A

When heredando d multiples interfacez, todas deben de tirar la misma excepcion o jerarquiaa y enla implementacion deben de tirarse la de jerarquia menor la mas nieta o ninguna

Cuando se implementa una interfaz, metodo que tire excepcion no es necesario tirarla tambien en la implementacion, o se puede tirar la excepcion o una hija de la exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Putting a RuntimeException such as NullPointerException in the throws clause, is practically same as not putting it in the throws clause. In this case, as the base method has only a RuntimeException in its throws class, the overriding cannot throw any checked exception. It can throw any RuntimeException.

Java 5 onwards supports co-variant return types, which means that an overriding method can declare any sub-class of the return type declared in the overridden method as its return type.

A

If the parent throws a uncheck exception, the child can not throw a checked exception, only any unchecked exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Sii una interfaz tiene metodo default pero una hija lo redeclara como abstracto, se vuelve abstracto para los que implementen o extiendan esa interfaz hija

A

You cannot use super keyword to call a method defined in the super interface.

interface A { default void hello() { } }

interface B extends A {
default void hello() {
6super.hello();//This is NOT valid. A.super.hello();//This is valid.
} }

public class TestClass implements B {
public void hello() {
super.hello();//This is NOT valid.
A.super.hello(); //This is NOT valid because TestClass does not implement A directly.
B.super.hello(); //This is valid.
} }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

An enum cannot extend another enum or class. It may implement an interface though.

Enum constants cannot be instantiated/created using the new keyword.

A

Enum constructor is always private. You cannot make it public or protected. If an enum type has no constructor declarations, then a private constructor that takes no parameters is automatically provided.

An enum is implicitly final, which means you cannot extend it.

Compiler provides an enum with two public static methods automatically -values() and valueOf(String). The values method returns an array of its constants and valueOf method tries to match the String argument exactly (i.e. case sensitive) with an enum constant and returns that constant if successful otherwise it throws java.lang.IllegalArgumentException.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

facts about java.lang.Enum

A

It implements java.lang.Comparable (thus, an enum can be added to sorted collections such as SortedSet, TreeSet, and TreeMap).

It has a method ordinal(), which returns the index (starting with 0) of that constant i.e. the position of that constant in its enum declaration.

  1. It has a method name(), which returns the name of this enum constant, exactly as declared in its enum declaration.

Enums can be compared using ==.

it should be: case OFF instead of case Switch.OFF.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. collect(Collectors.groupingBy(Item::getCategory)) returns a Map where the keys are the Category values and the values are Lists of the elements.
  2. collect(Collectors.averagingDouble(priceF)) returns the average of the values returned by the priceF function when it is applied to each element of the Stream. In this case, a stream is created from the List of elements belonging to each categtory by the call to forEach.
A

ToDoubleFunction can take any object and returns a double.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

En clases genericas el diamante va luego del nombre de la clase, en los metodos va antes del tipo de retorno del metodo

A
Generic Class:
public class Box {
    // T stands for "Type"
    private T t;
}
is called:
Box integerBox;
Generic method
public static  boolean compare(Pair p1, Pair p2) {
}
is called:
boolean same = Util.compare(p1, p2);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

To customize the behavior of class serialization, the readObject and writeObject methods should be implemented.

A

Developers can change how a particular class is serialized by implementing two methods inside the class file.

These methods are: private void writeObject(ObjectOutputStream out) throws IOException;

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException;

Notice that both methods are (and must be) declared private, proving that neither method is inherited and overridden or overloaded. The trick here is that the virtual machine will automatically check to see if either method is declared during the corresponding method call. The virtual machine can call private methods of your class whenever it wants but no other objects can.

Thus, the integrity of the class is maintained and the serialization protocol can continue to work as normal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Object of any class that implements Serializable interface can be serialized, even final or private or whatever

A

Constructor of the class for an object being deserialized is never invoked.

However, constructor for the super class may be invoked if the super class does not implement serializable interface.

Any field that is not marked transient but points to an object of a class that does not implement Serializable, will cause an exception to be thrown

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Types of reduce

A

There are three versions of reduce : Optionalreduce(BinaryOperator accumulator) Performs a reduction on the elements of this stream, using an associative accumulation function, and returns an Optional describing the reduced value, if any. or returns an empty Optional

Treduce(T identity, BinaryOperator accumulator) Performs a reduction on the elements of this stream, using the provided identity value and an associative accumulation function, and returns the reduced value.

<u> Ureduce(U identity, BiFunction<u> accumulator, BinaryOperator<u> combiner) Performs a reduction on the elements of this stream, using the provided identity, accumulation and combining functions.</u></u></u>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

preparedStament vs Stament

A

PreparedStatement offers better performance when the same query is to be run multiple times with different parameter values.

PreparedStatement allows several additional SQL types such as BLOB and CLOB.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

methods are available in java.io.Console?

A
readPassword
reader
writer
readLine
format
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Overriding method can throw any exception as long as it is a subclass of any of the exceptions thrown by the overridden method.

It can also be a subclass of RuntimeException. eg. If the base class A has: void m1() throws IOException then overriding method in class B can be : void m1() throws FileNotFoundException because FileNotFoundException is a subclass of IOException.

A

Cuando se override, el hijo debe de tener el mismo o mayor acceso que el padre, es decir si el metodo es default, el hijo debe ser default, protected o public, mas no privado

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

c.setAutoCommit(false)

A

Tells to commit or not inmediately the changes to database,

To commit the changes you can call con.commit() or set autoCommit(true)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The natural order of enums is the order in which they are defined

A

Enums can be compared using ==.

An enum switch case label must be the unqualified name of an enumeration constant. So it should be: case OFF instead of case Switch.OFF.

17
Q

The lines() method has been added to java.io.BufferedReader in Java 1.8. It returns Stream.

A

d

18
Q

paralell streams can create one thread per element in the stream, so all the operations can happen the same way with each element.

A

List vals = Arrays.asList(“a”, “b”);
String join = vals.parallelStream().reduce(“_”,(a, b)->a.concat(b));
System.out.println(join);

Since we are creating a parallel stream, it is possible for both the elements of the stream to be processed by two different threads. In this case, the identity argument will be used to reduce both the elements. Thus, it will print _a_b. It is also possible that the result of the first reduction ( _a ) is reduced further using the second element (b). In this case, it will print _ab.

but the first element will always be _a since reduce maintains the order

19
Q

The average method of all numeric streams (i.e. IntStream, LongStream, and DoubleStream) returns an OptionalDouble and not a double. It never returns a null.

A

s

20
Q

The List.subList method returns a view backed by the original list. It doesn’t change the existing list. However, if you modify the sub list, the changes will be visible in the original list

A

a

21
Q

Overriding must return the same or a childish type and have the same signature

Overriding method can throw any RuntimeException
Overriding method cannot throw any checked exception that is not thrown by the parent

A

means that an overriding method can declare any sub-class of the return type declared in the overridden method as its return type

22
Q

When you create a FileOutputStream without specifying the append mode (which can be true or false), it overwrites the existing file.

A

s

23
Q

When a programmer does not define ANY constructor, the compiler inserts one automatically, the access modifier of which is same as that of the class

A

l

24
Q

Aun asignando prioridad a los thread, el orden no puede ser determinado y es mala practica

A

as

25
Q

A PreparedStatement is used for SQL statements that are executed multiple times with different values.

A CallableStatement is meant for executing a stored procedure, which has already been created in the database.

A

ps = c.prepareStatement(“INSERT INTO STUDENT VALUES (?, ?)”); //This is created only once //Once created, the PreparedStatement is compiled automatically.

ps. setInt(1, 111);
ps. setString(2, “Bob”);
ps. executeUpdate()

//computeMatrixForSales is a stored procedure that has already been created in the database. callableStatement = connection.prepareCall("{call computeMatrixForSales(?)}"); 
callableStatement.setInt(1, 1000); callableStatement.executeUpdate();
26
Q

Of all the collection classes of the java.util package, only Vector and Hashtable are Thread-safe

A

d

27
Q

If a synchronized method ends up throwing an exception to the caller, the lock acquired by the thread associated with this method due to the usage of the synchronized keyword is released automatically

A

las

28
Q

The lines() method has been added to java.io.BufferedReader in Java 1.8. It returns Stream.

A

lol