extundelete, Recover deleted files in Ubuntu

Download and make extundelete Run this script to download and compile extundelete from source Recover Files Get drive name Now that the extundelete is compiled, you would need to check the name of the drive to recover. And that can done by: Restore Restore all Restore a directory Restore a directory after a date/time In … [Read more…]

How to refactor enum to class

In this tutorial we will see how to refactor an enum.  I was recently working on a small project that was using an enum to manage some constants. But we had to change this enum to a class due to change of requirements. Overview Let’s say that a project was allowing users to choose from … [Read more…]

Compress and decompress byte[] in java

Here is a simple utility that compresses and decompresses a byte[] array. I have been using this utility to compress serialized objects before storing to and after retrieving them from the database. I have found it very useful. I have added a main method to just show that how the compression works. output:

Convert int[] to Integer[] and vice versa in java

Here is a simple example to convert primitive int array to Integer array and vice versa Using regular for-loop And the output is : Java 8 Using Stream APIs of Java 8. Commons Arrayutils If you are not using java 8 and still want to have a oneliner. Use ArrayUtils from commons-lang3. References http://www.oracle.com/technetwork/articles/java/ma14-java-se-8-streams-2177646.html https://en.wikipedia.org/wiki/Primitive_wrapper_class … [Read more…]

JavaFx Helloworld

In this example we will create a simple Helloworld application for JavaFx. I have added inline comments to the code. And here is the output   Notes In case you are using this HelloWorld in eclipse and you get the below warning. Access restriction: The type Pane is not accessible due to restriction on required … [Read more…]

Distribute your code in a unique style

So let’s have a look at a very interesting way of loading a class. UnIntrestingClass.java We have a very simple class. There is nothing special about it. It just prints text in constructor. ByteCodeGenerator.java This class prints the bytecode of the UnIntrestingClass. This class just shows how to print the bytecode. It prints InterestingLoadClass.java Let … [Read more…]

Convert byte[] array to String in Java

In this tutorial we will see how to convert a byte[] to String. It can be useful in cases where a String is stored as a byte[] array and needs to be converted to String. Java API Used This can be easily achieved by using the constructor provided by String class that accepts the byte[] … [Read more…]

Java abs() Method

Math.abs() method gives the absolute value of the passed argument. This method accepts arguments of type  int, float, long, double. Avaliable methods   Simple Example output:   Real World Example Problem I need the difference between two dates in minutes. The result should be always a positive number. Solution So here is my utility method … [Read more…]