How to get the current class name in Java?

Posted by Jessica Taylor | Updated on | Java


If you want to get the current class name in Java? The “$1″ is not “useless non-sense”. If your class is anonymous, a number is appended. If you don’t want the class itself, but its …

How to properly stop the Thread in Java?

Posted by Pinki | Updated on | Java


Want to properly stop the Thread in Java? In the IndexProcessor class you need a way of setting a flag which informs the thread that it will need to terminate, similar to the variable run …

Set margins in a LinearLayout programmatically

Posted by Editorial Staff | Updated on | Java


In this example, We have shared set margins in a LinearLayout programmatically. Java to create a LinearLayout with buttons that fill the screen with margins. Here is a little code to accomplish it:

How to clone ArrayList and also clone its contents?

Posted by Jessica Taylor | Updated on | Java


If you want to clone ArrayList and also clone its contents? You will need to iterate on the items, and clone them one by one, putting the clones in your result array as you go. …

Why are interface variables static and final by default?

Posted by Editorial Staff | Updated on | Java


In this example, We have shared Why are interface variables static and final by default? Interface variables are static because Java interfaces cannot be instantiated in their own right; the value of the variable must …

Checking for a null int value from a Java ResultSet

Posted by Ramesh Singh | Updated on | Java


Checking for a null int value from a Java ResultSet. The default for ResultSet.getInt when the field value is NULL is to return 0, which is also the default value for your iVal declaration. In …

How to create a memory leak in Java?

Posted by Jessica Taylor | Updated on | Java


Want to create a memory leak in Java? A simple thing to do is to use a HashSet with an incorrect (or non-existent) hashCode() or equals(), and then keep adding “duplicates”. Instead of ignoring duplicates …

How to convert a String to an InputStream object in Java?

Posted by Jessica Taylor | Updated on | Java


How to convert a String to an InputStream object in Java? We can convert a String to an InputStream object by using the ByteArrayInputStream class. Use the below Java example to convert a String to …

How to implement LongPredicate using lambda and method reference in Java?

Posted by Pooja Joshi | Updated on | Java


Want to implement LongPredicate using lambda and method reference in Java? Use the below example of Lambda Expression:

How to set HttpResponse timeout for Android in Java?

Posted by Editorial Staff | Updated on | Android Java


How to set HttpResponse timeout for Android in Java? In my example, two timeouts are set. The connection timeout throws java.net.SocketTimeoutException: Socket is not connected and the socket timeout java.net.SocketTimeoutException: The operation timed out. If …

How to combine paths in Java?

Posted by Editorial Staff | Updated on | Java


Is you want to combine paths in Java? You can combine paths by using the resolve method. You pass in a partial path , which is a path that does not include a root element, …

How to add an image to a jpanel in java?

Posted by Pinki | Updated on | Java


Want to add an image to a jpanel in java? Use the below Java program to add an image to a jpanel.

Difference between final and effectively final

Posted by Editorial Staff | Updated on | Java


In this example, We have shared difference between final and effectively final. For example, suppose that the variable numberLength is not declared final, and you add the marked assignment statement in the PhoneNumber constructor:

How to create a temporary folder in Java?

Posted by Rohit Kumar | Updated on | Java


Want to create a temporary folder in Java? Use the below Java program to create a temporary directory using Java.

How to configure encoding in Maven?

Posted by Editorial Staff | Updated on | Java


If you want to configure encoding in Maven? Use this reporting plugins. In the documentation of the failsafe-maven-plugin (http://maven.apache.org/plugins/maven-failsafe-plugin/integration-test-mojo.html) I found, that the configuration – of course – uses ${project.reporting.outputEncoding} by default. So I added …