Type inference is a compiler algorhytm that finds out omitted generic types by looking at the context. The algorhytm works out the most specific type that fits any possible valid arguments.
Here are some examples:
1) You can omit a parametrized type with the use of a diamon construct:
List<String> list = new ArrayList<>();
The full sentence would be:
List<String> list = new ArrayList<String>();
2) You can omit the parameter type:
Stack.push(10);
The full sentence would be:
A fail-fast iterator fails if the data structure has been changed by another thread or a method other than an iterator's method. This is not a guaranteed behaviour as the counter is not synchonized.
A fail-fast iterator create a copy of the data structure, so there can't be any collision. However there is an overhead in creating the clone.
The only practical difference for the developer is that a fail-fast iterator can throw ConcurrentModificationException, whereas a fail-safe iterator cannot throw it.
An example of collection that returns a fail-fast iterator is HashMap.
An interrupt is a way to tell a thread to terminate, giving it time to complete any important tasks first.
When an interrupt is received, the status "interrupted" is set to true:
public void cancel() { interrupt(); }
If the thread is responsive to interruptions, we might decide to exit:
public void run() { while(!Thread.currentThread().isInterrupted()) { // Do something } }
Or we can throw InterruptedException:
public static void sleep(long millis) throws InterruptedException { while (true) {
MapReduce is an algorithm invented by Google for processing large data sets in parallel on multi processor or distributed systems. It's highly scalable and improves performance.
A map function performs filtering or sorting on sub-sets of the data. A reduce function aggregate the partial results.
For example, a mapreduce algorithm is run to find tallest building in each city. Two of the map functions return the following results:
London, The Shard = 309 London, One Canada Water = 235
The reduce function returns a single result:
London, The Shard = 309
NumberFormat is the class used to parse and format numbers for a specific locale.
It's abstract and cannot be instantiated, but returns an instance for a specific locale.
NumberFormat nf = NumberFormat.getInstance(Locale.GERMANY);
Or the default one:
NumberFormat nf = NumberFormat.getInstance();
Then the instance can now be used to format a number:
System.out.println(nf.format(13.4563));
Or parse a string:
double parsedNum = (double) nf.parse("14,456");
An utility class is a class that:
An utility class abide by the following rules:
Here's an example:
public final class Translator { private Translator() {} public static String translate(String text) { // some logic } // Other methods }
A media type is a general category of data content in internet. It was originally known as MIME type and devised to define the content of e-mails. The name changed, because now the term is used in a wider range of applications.
Content type is the same as media type, but it is used in the context of an HTTP header.
Content-Type: application/x-www-form-urlencoded
A media type is composed of a type and a subtype. Common media types are:
A default method is an interface method that adds new functionality and at the same time is backward compatible.
This is achieved with a default implementation, that doesn't break previous implementations of the interface. By defaut all the methods of an interface are abstract, however this is not the case of a default method.
public interface Runnable { void run(); default int getThreadId() { // implementation } }
You can extend an interface with a default method and:
When you develop Maven dependencies for your projects, you want to be able to debug those dependencies or modify the code, as you debug the main application.
You can easily do that in Eclipse, by importing the main application and the dependent projects.
However, it is not so straightforward in Intellij.
In Intellij you can debug a Maven dependency, by downloading the source code:
1) Right click on the project and select "Maven > Download sources" 2) Right click on the project and select "Maven > Reimport"
A condition is a synchronization object used to for a particular condition on shared data.
The use of a Condition object is equivalent to the use of wait() and notify(). However, in the former case it's possible to set multiple conditions for the same monitor.
here's the equivalence:
object.wait() --> condition.await() object.notify() --> condition.signal()
Another difference is that a condition can only be associated to an explicit lock like LockReentrant.
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.