Category: Java

Java – How to convert a bool or string value to Boolean in Java ?

Problem Statement You need to convert a boolean value of string value to Boolean type in your java program. Solution Use the Boolean class’s constructor and pass the corresponsing parameter to change it. Below is the sample code snippet demonstrating how to do it. The output of the above program is Abundantcode.com Java Tutorials false false

Java How to – Find if the Class exists or not

Problem Statement You need to test for the presence of a class from your java program. Solution Use Class.forName method to find if a particular class exists. Below is a sample code snippet demonstrating the usage of Class.forName to find out if the class “test” exists. Note that this method throws an exception incase the class cannot be loaded. Note: You need to pass the…

Keywords in Java

Below are some of the well known keywords in Java Keywords in Java abstractassertbooleanbreakbytecasecatchcharclassconstcontinuedefaultdodoubleelseenumextendsfinalfinallyfloatforgotoifimplementsimportinstanceofintinterfacelongnativenewpackageprivateprotectedpublicreturnshortstaticstrictfpsuperswitchsynchronizedthisthrowthrowstransienttryvoidvolatilewhile

Mocking frameworks for Java Developers

There are plenty of mocking framework for java that are available for developers. Below are some of the links or collections of mocking frameworks for Java Developers Mocking frameworks for Java Developers PowerMock JtestR EasyMock Mockito jmockit 

Java Program #3

What is the output of the following Java program? Output false, true, false The iterator() method returns an iterator over the elements in the list in sequential order. It doesn’t return a List or a ListIterator object. You can get a ListIterator object by invoking the listIterator method.

Tools to Convert Java to C# Source Code

There are times when a developer would have done a project using Java and would want to reuse some of the data classes or business logic to C# for developing application on different platform. Tools to Convert Java to C# Source Code Below are some of the tools that can be used to convert the code from Java to C# . Sharpen This is a…

Java – How to Check if a string is a valid number?

Problem statement You need to check if a input string contain a valid number or not. Solution Use the appropriate wrapper class for converting the string to numeric formats. For example Double to convert string to double as shown below. When the input is a invalid number , the NumberFormatException is caused which needs to be handled by the developers.

How to sort an array using Comparator in Java ?

The Arrays.sort method in java lets the developers to sort an array of objects. The sort method also accepts the comparator object which can contain the sorting logic. How to sort an array using Comparator in Java ? Below is a sample code snippet demonstrating the usage of the Arrays.sort method with the comparator.