test chivos Flashcards

1
Q

<p>Metodos siempre del objecto

| Variables siempre de la referencia</p>

A

<p>si el metodo del objeto llama a una variable en ambas,, se llama a la variable del objeto</p>

, el metodo siempre va sobre el objeto a menos que el metodo sea estatico, en ese caso va sobre la referencia y debe llamarse como a un metodo estatico, HOLA.METODOESTATICO(); si la referencia fuera una interfaz sino no compila

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

<p>IntSupplier, DoubleSupplier and so on, must return a primitive and not null otherwise</p>

A

<p>nullpointerException</p>

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

<p>binarySearch returns?</p>

A

<p>index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.</p>

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

<p>In arrayDeque what does the add, push and offer methods do</p>

A

<p>adds the element to the end while push() is a stack method that adds the element to the front.

offer adds elements to the end but offerFirst adds the element to the front</p>

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

<p>In ArrayDeque what does de pop and remove methods do</p>

A

<p>Pop() removes the element from the front

| Remove() removes the element from the front.</p>

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

<p>Since Queue is a FIFO add to the end and remove from the front structure has the methods¡</p>

A

<p>offer(e)/add(e) to add to the end
poll()/remove()(for removing an element from the front or head)

add(e) throws an exception if the element cannot be added to the queue because of lack of capacity, while offer(e) does not.</p>

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

<p>Since Stack is a LIFO add to the front and remove from the front structure has the methods</p>

A

<p>push(e) and pop() for this purpose, where push adds to the front and pop removes from the front.</p>

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

<p>pollFirst()/pollLast()?

| removeFirst()/removeLast(</p>

A

<p>pollFirst and pollLast will remove elements from the front and from the end respectively.

removeFirst()/removeLast remove elements from the front and from the end respectively.

These methods differ from pollFirst/pollLast only in that they throw an exception if this deque is empty.</p>

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

<p>offerFirst(e)/offerLast(e)

| addFirst(e)/addLast(e)</p>

A

<p>offerFirst and offerLast will add elements to the front and to the end respectively.

addFirst and addLast will add elements to the front and to the end respectively.</p>

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

<p>peek(), peekFirst():
peekLast()
element():</p>

A

<p>peek(), peekFirst(): return the first element from the front of the queue but does not remove it from the queue.

peekLast() : returns the last element from the end of the queue but does not remove it from the queue.

element(): retrieves, but does not remove, the head of the queue represented by this deque (in other words, the first element of this deque). This method differs from peek only in that it throws an exception if this deque is empty.</p>

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

<p>Period p = Period.between(LocalDate.now(), LocalDate.of(2015, Month.SEPTEMBER, 1));</p>

A

<p>Note that if the second date is before the first date, a minus sign is included in the output.</p>

if working with timeZones, try to convert both to global timezone and then do the math or just invert the order

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

<p>Design pattern</p>

A

<p>Is a common solutions to software development problem, example, singleton, inmutability, etc</p>

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

<p>lower and higher,</p>

A

<p>is strictly lower and the other is lower or equal</p>

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

<p>CyclicBarrier</p>

A

<p>allows multiple threads to run independently but wait at one point until all of the coordinating threads arrive at that point.

It is like multiple cyclists taking different routes to reach a particular junction. They may arrive at different times but they will wait there until everyone arrives. Once everyone is there, they can go on futher independent of each other.</p>

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

<p>Static method on interfaces must be call directly on the interface: like not on the object</p>

A

<p>Office.callingStaticMethod()</p>

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

<p>It is easy to identify which operations are intermediate and which are terminal. All intermediate operations return Stream (that means, they can be chained), while terminal operations don't.</p>

A

<p>filter, peek, and map are intermediate operations. Since the code does not invoke any terminal operation on the stream, the calls to these intermediate method do nothing. Therefore, no output is produced by the given code.

count, forEach, sum, allMatch, noneMatch, anyMatch, findFirst, and findAny are terminal operations.</p>

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

<p>ResultSetMetaData?</p>

A

<p>gives you the information about the result of executing a query. You can retrieve this object by calling getMetaData() on ResultSet.

Some important methods are:
getColumnCount(), getColumnName(int col), getColumnLabel(int col), and getColumnType(int col). Remember that the column index starts from 1.</p>

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

DeadLock
Starvation
LiveLock

A

Deadlock describes a situation where two or more threads are blocked forever, waiting for each other.

Starvation describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress.

Livelock: A thread often acts in response to the action of another thread. If the other thread’s action is also a response to the action of another thread, then livelock may result.

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

The number of threads created depends on how the ForkJoinPool is created. By default, it uses the number processors available.

A

The order of join() and compute() is critical. Remember that fork() causes the sub-task to be submitted to the pool and another thread can execute that task in parallel to the current thread. Therefore, if you call join() on the newly created sub task, you are basically waiting until that task finishes. This means you are using up both the threads (current thread and another thread from the pool that executes the subtask) for that sub task. Instead of waiting, you should use the current thread to compute another subtask and when done, wait for another thread to finish. This means, both the threads will execute their respective tasks in parallel instead of in sequence. Therefore, even though the final answer will be the same, the performance will not be the same.

20
Q

Durations and periods differ in their treatment of daylight savings time when added to ZonedDateTime. A Duration will add an exact number of seconds, thus a duration of one day is always exactly 24 hours. By contrast, a Period will add a conceptual day, trying to maintain the local time.

A

For example, consider adding a period of one day and a duration of one day to 18:00 on the evening before a daylight savings gap. The Period will add the conceptual day and result in a ZonedDateTime at 18:00 the following day. By contrast, the Duration will add exactly 24 hours, resulting in a ZonedDateTime at 19:00 the following day (assuming a one hour DST gap).

21
Q

Remember the following 4 points about Path.getName() method

A
  1. Indices for path names start from 0.
  2. Root (i.e. c:) is not included in path names.
  3. \ is NOT a part of a path name.
  4. If you pass a negative index or a value greater than or equal to the number of elements, or this path has zero name elements, java.lang.IllegalArgumentException is thrown. It DOES NOT return null.
22
Q

computeIfAbsent methods checks if the key exists in the map. If it does, the method just returns the value associated with that key. If it doesn’t, the method executes the Function, associates the value returned by that Function in the map with that key, and returns that value.

A

Remember that while compute and computeIfPresent take a BiFunction as an argument, computeIfAbsent takes a Function

23
Q

public V compute

A

Attempts to compute a mapping for the specified key and its current mapped value (or null if there is no current mapping). For example, to either create or append a String msg to a value mapping: map.compute(key, (k, v) -> (v == null) ? msg : v.concat(msg))

If the function returns null, the mapping is removed (or remains absent if initially absent). If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged. Parameters: key - key with which the specified value is to be associated remappingFunction - the function to compute a value Returns: the new value associated with the specified key, or null if none

24
Q

public V computeIfAbsent

A

If the specified key is not already associated with a value (or is mapped to null), attempts to compute its value using the given mapping function and enters it into this map unless null. If the function returns null no mapping is recorded. If the function itself throws an (unchecked) exception, the exception is rethrown, and no mapping is recorded. The most common usage is to construct a new object serving as an initial mapped value or memorized result, as in: map.computeIfAbsent(key, k -> new Value(f(k)));

Or to implement a multi-value map, Map>, supporting multiple values per key: map.computeIfAbsent(key, k -> new HashSet()).add(v); Parameters: key - key with which the specified value is to be associated mappingFunction - the function to compute a value Returns: the current (existing or computed) value associated with the specified key, or null if the computed value is null

25
Q

public V computeIfPresent

A

If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value. If the function returns null, the mapping is removed, the whole record is removed. If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged. Parameters: key - key with which the specified value is to be associated remappingFunction - the function to compute a value Returns: the new value associated with the specified key, or null if none

26
Q

The sum method of all numeric streams (i.e. IntStream, LongStream, and DoubleStream) returns a primitive value of the same type as the type of the stream

average method which always returns an OptionalDouble for all numeric streams.

A

If the stream has no elements, average returns an empty OptionalDouble and not a null.

27
Q

Order of getting properties

A

1) Zoo_fr_FR.java
2) Zoo_fr_FR.properties
3) Zoo_fr.java
4) Zoo_fr.properties
5) Zoo_en_US.java (the default locale)
6) Zoo_en_US.properties
7) Zoo_en.java
8) Zoo_en.properties
9) Zoo.java
10) Zoo.properties
11) If still not found, throw MissingResourceException.

28
Q

NumberFormat format() method

A

Call this method on a NumberFormat object with a number as an argument to format it in the specified locale that is saved in the NumberFormat object.

29
Q

NumberFormat parse() method

A

Parses text from the beginning of the given string to produce a number. Returns a Number object.

The parse method parses only the beginning of a string. After it reaches a character that cannot be parsed, the parsing stops and the value is returned.

NumberFormat nf = NumberFormat.getInstance();
String one = “456abc”;
String two = “-2.5165x10”;
String three = “x85.3”;
System.out.println(nf.parse(one)); // 456 System.out.println(nf.parse(two)); // -2.5165 System.out.println(nf.parse(three));// throws ParseException

30
Q

When declaring a Map, you should send the exact type to it, like Map> stateCitiesMap = new HashMap<>(); you can send only List, not childs of List like arrayList

A

a

31
Q

HashMap supports adding null key as well as null values but ConcurrentHashMap does not.

A

a

32
Q

assertions

A

Assertions can be enabled or disabled for specific packages or classes. To specify a class, use the class name. To specify a package, use the package name followed by “…” (three dots):
java -ea: myPackage.MyProgram
java -da:… myPackage.MyProgram

To enable assertion for one package and disable for other you can use:
java -ea:… -da:… myPackage.MyProgram

You can enable or disable assertions in the unnamed root (default)package (the one in the current directory) using the following commands:

java -ea:… myPackage.myProgram
java -da:… myPackage.myProgram

Note that when you use a package name in the ea or da flag, the flag applies to that package as well as its subpackages. For example,
java -ea:com… -da:com.enthuware… com.enthuware.Main

The above command first enables assertions for all the classes in com as well as for the classes in the subpackages of com. It then disables assertions for classes in package com.enthuware and its subpackages.

33
Q

private fields of innerclases can be accesible on outer clases

A

a

34
Q

Starting JDBC 4.0, the JDBC Driver class is not required to be loaded explicitly in the code any more.

A

l

35
Q

you cant pass arguments to method references hola::myhola(x) will not compile

A

as

36
Q

Files options

A

REPLACE_EXISTING If the target file exists, then the target file is replaced if it is not a non-empty directory. If the target file exists and is a symbolic link, then the symbolic link itself, not the target of the link, is replaced.

COPY_ATTRIBUTES Attempts to copy the file attributes associated with this file to the target file. The exact file attributes that are copied is platform and file system dependent and therefore unspecified. Minimally, the last-modified-time is copied to the target file if supported by both the source and target file store. Copying of file timestamps may result in precision loss.

NOFOLLOW_LINKS Symbolic links are not followed. If the file is a symbolic link, then the symbolic link itself, not the target of the link, is copied. It is implementation specific if file attributes can be copied to the new link. In other words, the COPY_ATTRIBUTES option may be ignored when copying a symbolic link. An implementation of this interface may support additional implementation specific options.

37
Q

Cuando se trabaje con hashmap, hashset siempre debe de implementar equals y hashcode() en los objetos para garantizar su correcto funcionamiento

A

as

38
Q

path.normalize() no elimina al elemento raiz, por ejemplo Path p1 = Paths.get(“c:\..\temp\test.txt”); System.out.println(p1.normalize().toUri());

devolveria
file:///c:/temp/test.txt, no remueve al raiz

A

sss

39
Q

most of the I/O operations (such as opening a stream on a file, reading or writing from/to a file) throw IOException and needs to be handleds

A

s

40
Q

A synchronized method can call another synchronized method in its body.

Making a synchronized method recursive will not cause a deadlock.

A synchronized method can call a non-synchronized method in its body.

A

A synchronized method is similar to any other method except that only one thread can be in it at a given time.

41
Q

For a class to be serializable only the class needs to implement Serializable interface.

A

Also remember that if a super class declares that it implements Serializable, all its subclasses automatically become serializable.

A thread exclusively owns the intrinsic lock between the time it has acquired the lock and released the lock.

Java does not provide any mechanism to detect, prevent or resolve a deadlock.

42
Q

Overloading solo considera parametros y su orden, no retorno, si solo cambia el retorno, tira error de compilacion

A

as

43
Q

las clases implementan comparable y los metodos “sort” utilizan comparator

A

comparator es compare

comparable es compareTo

44
Q

static blocks dont have access to instance variables or methods

A

s

45
Q

Having ambiguous fields or methods does not cause any problems by itself but referring to such fields/methods in an ambiguous way will cause an error at compile time

A
// Filename: TestClass.java
class TestClass implements T1, T2{
   public void m1(){}
}
interface T1{
   int VALUE = 1;
   void m1();
}
interface T2{
   int VALUE = 2;
   void m1();
}

So you cannot call : System.out.println(VALUE); because it will be ambiguous (there are two VALUE definitions). But the following lines are valid : TestClass tc = new TestClass(); System.out.println(( ( T1) tc).VALUE);

46
Q

Always check that resources in a try wit resources, implement auocloseable

A

a