Friday, November 18, 2016
Tuesday, May 10, 2016
Java: Variables in interfaces
Concept of variables in interfaces is allowed in Java, but the concept is different. Variables defined in interfaces are always static and final.
Check this for more details.
Check this for more details.
Wednesday, May 4, 2016
Java syntax hack
These are equivalent code segments:
Hacky syntax:
Map map = new HashMap() {{
put("key", "value");
}};
Normal syntax:
Map map = new HashMap();
map.put("key", "value");
Decryption of encrypted syntax
First set of braces is the anonymous inner class (subclassing HashMap). The second set of braces is an instance initializer (rather than a static one) which then sets the values on your HashMap.Usages
This hacky syntax could be used gracefully when initializing a class member. This way you will avoid adding code to constructor(s) or in static initializer of the class.Anonymous class that “extends” other class or “implements” some interface in Java?
Anonymous classes in Java are defined in this way:
Syntax for implementing some interface:
Syntax for extending other class (is the same):
Syntax for implementing some interface:
Runnable r = new Runnable() {
public void run() { ... }
};
Syntax for extending other class (is the same):
SomeClass x = new SomeClass() {
...
};
Wednesday, March 16, 2016
BigDecimal
Tutorials:
1. http://www.javaworld.com/article/2075315/core-java/make-cents-with-bigdecimal.html
2. https://topic.alibabacloud.com/a/how-to-use-java-bigdecimala-tutorial__java_1_27_20230422.html
Discussions:
Double vs BigDecimal: http://stackoverflow.com/questions/3413448/double-vs-bigdecimal
Most important:
1. BigDecimals are immutable.
1. http://www.javaworld.com/article/2075315/core-java/make-cents-with-bigdecimal.html
2. https://topic.alibabacloud.com/a/how-to-use-java-bigdecimala-tutorial__java_1_27_20230422.html
Discussions:
Double vs BigDecimal: http://stackoverflow.com/questions/3413448/double-vs-bigdecimal
Most important:
1. BigDecimals are immutable.
Thursday, January 14, 2016
Brief view in JAX-RS (Java API for RESTful Web Services)
What is JAX-RS
Java API for RESTful Web Services (JAX-RS) is a Java
programming language API that provides support in creating web services
according to the Representational State Transfer (REST) architectural
pattern.
JAX-RS is an official part of Java EE 6.
JAX-RS is an official part of Java EE 6.
Annotations in JAX-RS
JAX-RS uses these annotations:
@Pathspecifies the relative path for a resource class or method.@GET,@PUT,@POST,@DELETEand@HEADspecify the HTTP request type of a resource.@Producesspecifies the response Internet media types (used for content negotiation).@Consumesspecifies the accepted request Internet media types.
@PathParambinds the method parameter to a path segment.@QueryParambinds the method parameter to the value of an HTTP query parameter.@MatrixParambinds the method parameter to the value of an HTTP matrix parameter.@HeaderParambinds the method parameter to an HTTP header value.@CookieParambinds the method parameter to a cookie value.@FormParambinds the method parameter to a form value.@DefaultValuespecifies a default value for the above bindings when the key is not found.@Contextreturns the entire context of the object (for example@Context HttpServletRequest request).
Wednesday, November 25, 2015
Linux console commands test for developers
Questions for an linux interview:
1. extract lines containing ERROR from log file - grep
1.1 ignore-case grep
1.2 recursive grep
2. watch a log file when it grows - tail -f
3. check drives for free space: df -h
4. lsof - checks which processes are opened an file/folder
5. install packages to linux - apt-get install
6. look for a file on the drive - locate
7. I have written "locate hard-to-remember-file-o48275666.txt" before 100 console commands. How to remember file name when I remember only the prefix "hard-to-remember-"? - Ctrl + R locate hard-to-remember-file-
8. how to force stop all java processes
10. list all processes and sort them by memory usage / view free memory and swap usage
1. extract lines containing ERROR from log file - grep
1.1 ignore-case grep
1.2 recursive grep
2. watch a log file when it grows - tail -f
3. check drives for free space: df -h
4. lsof - checks which processes are opened an file/folder
5. install packages to linux - apt-get install
6. look for a file on the drive - locate
7. I have written "locate hard-to-remember-file-o48275666.txt" before 100 console commands. How to remember file name when I remember only the prefix "hard-to-remember-"? - Ctrl + R locate hard-to-remember-file-
8. how to force stop all java processes
10. list all processes and sort them by memory usage / view free memory and swap usage
Subscribe to:
Posts (Atom)