test chivos Flashcards
(46 cards)
<p>Metodos siempre del objecto
| Variables siempre de la referencia</p>
<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
<p>IntSupplier, DoubleSupplier and so on, must return a primitive and not null otherwise</p>
<p>nullpointerException</p>
<p>binarySearch returns?</p>
<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>
<p>In arrayDeque what does the add, push and offer methods do</p>
<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>
<p>In ArrayDeque what does de pop and remove methods do</p>
<p>Pop() removes the element from the front
| Remove() removes the element from the front.</p>
<p>Since Queue is a FIFO add to the end and remove from the front structure has the methods¡</p>
<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>
<p>Since Stack is a LIFO add to the front and remove from the front structure has the methods</p>
<p>push(e) and pop() for this purpose, where push adds to the front and pop removes from the front.</p>
<p>pollFirst()/pollLast()?
| removeFirst()/removeLast(</p>
<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>
<p>offerFirst(e)/offerLast(e)
| addFirst(e)/addLast(e)</p>
<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>
<p>peek(), peekFirst():
peekLast()
element():</p>
<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>
<p>Period p = Period.between(LocalDate.now(), LocalDate.of(2015, Month.SEPTEMBER, 1));</p>
<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
<p>Design pattern</p>
<p>Is a common solutions to software development problem, example, singleton, inmutability, etc</p>
<p>lower and higher,</p>
<p>is strictly lower and the other is lower or equal</p>
<p>CyclicBarrier</p>
<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>
<p>Static method on interfaces must be call directly on the interface: like not on the object</p>
<p>Office.callingStaticMethod()</p>
<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>
<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>
<p>ResultSetMetaData?</p>
<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>
DeadLock
Starvation
LiveLock
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.
The number of threads created depends on how the ForkJoinPool is created. By default, it uses the number processors available.
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.
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.
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).
Remember the following 4 points about Path.getName() method
- Indices for path names start from 0.
- Root (i.e. c:) is not included in path names.
- \ is NOT a part of a path name.
- 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.
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.
Remember that while compute and computeIfPresent take a BiFunction as an argument, computeIfAbsent takes a Function
public V compute
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
public V computeIfAbsent
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