Exception Handling in Java

Definition: An exception is an event, which occurs during the execution of a program, that disrupts the normal flow of a program’s instruction. Why do we need Exception Handling? 1. To separate “error handling” code from the “regular code”. 2. The programmer use exceptions to indicate that an error has occurred. Lets see an example […]

Share
Continue reading →

Getting User Input using Java

In order to get an input from the user, there is a special class used called as Scanner. The Scanner class is defined by java. Whenever you want to use a scanner class, you have to import it as import java.util.Scanner; which is shown in the example below. Example As shown in the above code, […]

Share
Continue reading →

Validate checksum in Linux.

For example there is one file FileName.txt in server with following checksum, sha1 : 69c7b0f0d46dfc7a0q693e725534cd20f6d98a1e md5 : 9e9021c288c0f107ed772baa6ac49f86 You downloaded it in your pc and now you want to compare it’s checksum with server. 1. Validate sha1 checksum Open terminal. Type following command $ sha1sum FileName.txt | grep 69c7b0f0d46dfc7a0e693e725534cd20f6d98a1e You will get following output if […]

Share
Continue reading →

clone method in Java

clone method is a part of Object class like equal method. We can override clone method in any class. But to use clone method we need to implement Cloneable interface. Without implementing Cloneable interface you can not use clone method otherwise It will throws CloneNotSupportedException Clone method is used to create clone of object. IMPORTANT […]

Share
Continue reading →

Selection sort in java

This article is about selection sort in java For example we want to sort below array of integers. int[] index = { 10, 34, 4, 56, 7, 67, 88, 42 }; Selection sort start with first position means here it takes 10 and compares it with each and every other integers in array starting with […]

Share
Continue reading →

Java wait and sleep methods with example

Difference between wait and sleep 1. sleep() is a static method and It sends current running thread into the “Not Runnable” state. wait() is a instance method we are calling it using thread object and it is only affected for that object. 2. sleep() : Thread weak up after time expire or call interrupt() method. […]

Share
Continue reading →