Category: Java
Java – How to Convert Numbers to Objects and vice versa ?
Problem Statement You need convert numbers to objects and vice versa in your Java program. Solution There are times when you need to pass an object for a function where you have a numeric values. To convert numbers to objects and vice versa , you can use the corresponsing wrapper classes. For example , if you want to convert an int to Integer object or…
Java – How to use Packages to organize code ?
Problem Statement You need to use packages in java to organize your code. Solution Your Java program might the following Classes Interfaces Enums Other types There are times when your program might grow larger including th number of java classes used. You might want to organize these source files to that it is easier to maintain and avoid other issues like class name conflicts. Inorder…
Java – How to round floating point number to integer ?
Problem Statement You need to round the floating-point numbers to integers in Java. Solution When you cast a floating value to integer in Java , the value gets truncated. For example , the value 7.8989 when casted to integer will become 7. In order to round he floating-point numbers correctly , you can use the Math.round() method. The Math.round method has a 2 overloaded forms….
Java – How to decode string from Hexadecimal and Octal to Integer in Java ?
Problem Statement You need to decode a string from hexadecimal to integer in java as well as octal to integer. Solution Use the decode method defined in the Integer class to decode an hexadecimal and octal number to integer as shown below. The output of the above program is 255 46
Java Compiler Error – ‘(‘ or ‘[‘ expected
What is the Java Compiler Error ? error: ‘(‘ or ‘[‘ expected Reason for the Error You will likely get this error when you have missed [] when declaring an array in Java. For example, the below code snippet results in the ‘(‘ or ‘[‘ expected error in Java. There are other reasons why you might this error too. For example, you have either missed…
Java – How to Check if integer is multiple of a number?
Problem Statement You need to check if the integer number is a multiple of a number in Java. Solution Use the modulus operator and check the remainder to find it out. Below is a sample code snippet demonstrating how to find if the number is a multiple of 4.
How to Declare an Octal literal in Java ?
Problem Statement You want to declare an octal literal in Java. Solution Prefix the value with 0. A literal that contains leading zero is an octal number. The output of the above program will be 8 21
Java Program to display "Hello, World!"
Problem Write a program in Java to display “Hello, World!” on the screen. Java Program to display “Hello, World!” in Console Window. This is a simple Java program that displays “Hello, World!” on the console window. Output Hello, World!
Java Program to copy range of elements from an array
The Java’s Arrays class provides a static function called Arrays.copyOfRange that helps the developers to copy a range of elements from one array to another. How to Copy range of elements from an array in Java ? Below is an example that demonstrates the copying of the range of objects from one array to another using Arrays.copyOfRange. Output Source Array ———— Java Abundantcode.com MCA Lab…
For loop in Java
The for loop in java lets the developers to iterate over a list of values . The for loop executes until the exit condition matches . Following the syntax of the for loop in java for (initialization; condition;increment){statement(s)} The initialization expression is used to initialize the loop and is executed as soon as the loop begins. The termination condition is verified every time and the…
Top 10 Open source Full Text Search libraries
Are you looking at implementing the full text search with in your website ? . In this blog post , we will list out the top 10 open source full text search libraries which you can use in your website. Top 10 Open source Full Text Search libraries 1. Lucene Lucene is one of the most popular java based search engine library that offers real…
Microsoft Band and Android(Java) – Connect to the Band
Below is the sample code snippet demonstrating how to connect to the first microsoft band that is paired using the BandInfo and BandClient object. How to Connect to the Microsoft Band from android application using Java ? How to get the list of paired bands from the android application using java.
While Loop example in Java
The while loop in java lets the developers execute a block of statements continuously until a particular condition is true . The syntax of the while loop in java can be written as while(expression){statement(s)} The while loop evaluates the expression which returns true and executes until the expression returns false. While Loop example in Java Below is a sample code snippet demonstrating the usage of…
Java – How to get the String representation of the Boolean value in Java ?
Problem statement You need to convert the Boolean value to string and display the string representation of the same. Solution Use the toString static method defined in the Boolean class for the conversion. The output of the above program is Abundantcode.com Java Tutorials false
JAR file operations in Java
Below are some of the common JAR File operations in Java. JAR file operations in Java jar cf This command creates a JAR file.Syntax : jar cf jar-file input-file jar tf This command is used to view the contents of the JAR file.Syntax : jar tf jar-file jar xf This command is used to extract the contents of a JAR file.Syntax : jar xf jar-file
How to Compare two arrays in Java ?
You can compare arrays in java using the Array.deepEquals() method . The Array.deepEquals() method in Java lets the developers to compare array objects and return true if both the arrays contains the same objects. How to Compare two arrays in Java ? Below is a sample code snippet demonstrating the usage of Array.deepEquals() to compare two arrays. Output Comparing input and input2————————–trueComparing input and input3————————–false
Java Program #1
What is the output of the following Java program? Output a b c
How to Check if Integer is a multiple of a number in Java?
If you want to check if the integer value is a multiple of a number in Java , you can use the modulus (%) operator . If you get the result as zero , then it is considered as multiple of a number. How to Check if Integer is a multiple of a number in Java? Below is a sample code snippet demonstrating the usage…
Top Java based Content Management Systems (CMS)
If you are a Java developer and looking for the top Java based Content Management Systems (CMS) . Here we go. Top Java based Content Management Systems (CMS) Below are some of the top content management systems (CMS) that are based on Java platform. Some of them are open source and few are commercial software’s. Apache Roller Hippo CMS Alfresco OpenWGA OpenCMS XWiki LogicalDoc Jahia…
Best Java Equivalent for LINQ (C#)
LINQ Query and Lambda expressions are one of the popular features of C# which helped the .NET developers in many ways. If you are a Java developer and wondering is there anything similar to this in Java ? ,this post will provide some insights on the additional APIs which could bring in the similar functionality Best Java Equivalent for LINQ (C#) jaque Another Java integrated…