Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 576b784

Browse files
author
golonzovsky
committed
Merge remote-tracking branch 'origin/master' into golonzovsky
2 parents c2ce4fe + 0cfc5d5 commit 576b784

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

Java Assertions.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
------------------------------------------------------------------------------------------
2+
Java Assertions
3+
------------------------------------------------------------------------------------------

Java Testing With JUnit.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
------------------------------------------------------------------------------------------
2+
JUnit
3+
------------------------------------------------------------------------------------------

Java Version Specific.txt

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Java 5 specifics
2020

2121
It is a generic type that is parametrized with an unbounded ( <?> ) or bounded ( <? extends T> ot <? super T> ) wildcard type. A wildcard type basically tells us that the type parameter can be any type.
2222

23-
4. What is Autoboxing/unboxing and what are its advantages/pitfalls?
23+
4. What is Autoboxing/unboxing?
2424

2525
Autoboxing is automatic casting of variables of primitive types to corresponding wrapper class. Unboxing is the inverted cast.
2626
Useful to reduce the amount of code to be written. Pitfalls: can be unintentionally slow if used in a loop. Also care has to be taken with cached values. (e.g. a pool of Integers from -128 to +127)
@@ -34,24 +34,102 @@ Java 5 specifics
3434
5. Enables to associate additional data with enum constants
3535

3636
6. What are Annotations and which predefined by the language specification does one know (@Deprecated, @Override, @SuppressWarnings)
37+
38+
From http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html
39+
Annotations provide data about a program that is not part of the program itself. They have no direct effect on the operation of the code they annotate. Annotations can be applied to a program's declarations of classes, fields, methods, and other program elements.
3740

3841
@Deprecated -- to inform that the method is deprecated
3942
@Override -- to inform that this method has to override a method in a superclass. Helps to find errors.
4043
@SuppressWarnings -- to suppress warnings. E.g. warnings generated when doing potentially unsafe cast
4144

4245
16. Annotation retentions policies and why they are in place?
4346

44-
TODO: ...
47+
The retention policies specify how long annotations are to retained.
48+
49+
CLASS: Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time. Useful for bytecode postprocessing. Cannot be inspected at run-time with reflection getAnnotations
50+
51+
RUNTIME: Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively. (@Deprecated)
52+
53+
SOURCE: Annotations are to be discarded by the compiler. (Example: @Override, @SuppressWarnings)
4554

4655
17. Suppose you would like to reuse a class in different contexts would you use annotations or external configuration? (i.e. annotation introduce dependencies).
56+
57+
Good discussion of this question can be found here
58+
http://javidjamae.com/2006/11/19/annotations-vs-xml/
59+
4760

4861
------------------------------------------------------------------------------------------
4962
Java 7 specifics
5063
------------------------------------------------------------------------------------------
5164
1. Try with resource
65+
66+
The try-with-resources statement is a try statement that declares one or more resources. A resource is an object that must be closed after the program is finished with it. The try-with-resources statement ensures that each resource is closed at the end of the statement. Any object that implements java.lang.AutoCloseable, which includes all objects which implement java.io.Closeable, can be used as a resource.
67+
68+
Example
69+
70+
static String readFirstLineFromFile(String path) throws IOException {
71+
try (BufferedReader br =
72+
new BufferedReader(new FileReader(path))) {
73+
return br.readLine();
74+
}
75+
}
76+
5277
2. Diamond operator
78+
79+
In Java 7 writing the type parameters twice is no longer needed.
80+
Example:
81+
82+
Instead of writing HashMap<String, Integer> hm = new HashMap<String,Integer>();
83+
one can just write HashMap<String, Integer> hm = new HashMap<>();
84+
The latter is now preferable
85+
5386
3. Better exception catching
87+
88+
In Java 7 the same processing can be performed for a whole list of exceptions:
89+
90+
try {
91+
...
92+
} catch (ExceptionType1 | ExceptionType2 | ExceptionType3 ex){
93+
// do some processing
94+
}
95+
96+
Note that these exceptions cannot belong to the same hierarchy (none is subclass or superclass of the other)
97+
5498
4. Strings in switch statement
99+
100+
String dayOfWeek = "Mon";
101+
switch (dayOfWeek.toLowerCase()) {
102+
case "mon" :
103+
//do something
104+
break;
105+
case "tue" :
106+
//do something
107+
break;
108+
...
109+
default :
110+
//do something
111+
break;
112+
}
113+
55114
5. Numeric literals with underscores
115+
116+
From http://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html
117+
In Java SE 7 and later, any number of underscore characters (_) can appear anywhere between digits in a numerical literal. This feature enables you, for example, to separate groups of digits in numeric literals, which can improve the readability of your code
118+
119+
long creditCardNumber = 1234_5678_9012_3456L;
120+
long socialSecurityNumber = 999_99_9999L;
121+
float pi = 3.14_15F;
122+
123+
56124
6. New I/O.
125+
126+
Lots of stuff here. More info cat be found at
127+
http://docs.oracle.com/javase/tutorial/essential/io/fileio.html
128+
http://www.drdobbs.com/jvm/java-se-7-new-file-io/231600403
129+
57130
7. Fork/Join framework
131+
132+
The fork / join framework is an implementation of the ExecutorService interface that helps you take advantage of multiple processors. It is designed for work that can be broken into smaller pieces recursively.
133+
134+
Example can be found here
135+
http://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html

0 commit comments

Comments
 (0)