devxlogo

Java

Creating a Link to a File in Java

There are times when we need to reflect the changes made to a file in a different file as well. Mostly, they are made available in a common place so

Understanding the Long Data Type in Java

Java long behaves differently when used with the letter L and without it. Code snippet public class JavaLong{ public static void main(String args[]) { JavaLong javaLong = new JavaLong(); javaLong.proceed();

Simple Annotation in Java

Annotations are similar to interfaces in that you can convey your own specifications that others will need to follow. Here we are defining an Annotation named ClassHeaderAnnote, which has few

Reducing Unbuffered Streams

InputStream in = new FileInputStream(file);int q;while ((q = in.read()) != -1) { …} The code above reads a file byte by byte. Every read() method call on the stream causes

Converting Numbers to Strings

“” + set.size()new Integer(set.size()).toString() The return type of the Set.size() method is int, but it is desired a conversion to String. These two lines do the conversion, but the first

Parsing and Converting Numbers in Java

int x = Integer.valueOf(str).intValue(); int y = Long.valueOf(Double.valueOf(str).longValue).intValue(); To use the API without allocating unnecessary objects use the following lines of code: int x = Integer.parseInt(str); int y = (int) Double.parseDouble(str);

How to Enable Java 9 GC Logs

GC logs are vital artifacts to troubleshoot memory/CPU related problems and optimize applications performance. In Sep 2017, the much-awaited Java 9 was released and GC logging was re-implemented using the