Tag: Java

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…

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…

Microsoft Band and Android(Java) – Add Permission Tags in the Manifest file

When working with the Microsoft Band using Java for an android app , it is necessary add the following permissions under the uses-permission tag of the AndroidManifest.xml. android.permission.BLUETOOTH com.microsoft.band.service.access.BIND_BAND_SERVICE How to add Permission Tags in the Manifest file to use Band SDK in Java ? The reason for adding this to the manifest file is that the app will be using the capabilities of the…

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

iText Library for Creating PDF documents in C# and Java

iText is a PDF Library or API (Application Programming Interface ) that allows the developers to generate PDF documents based on the data from database or XML file. iText is available in Java as well as .NET (C#) and uses LDF’s many interactive features. iText library allows the developers to add bookmarks , page numbers and watermarks. Know more about iText Library for Creating PDF…

Light Weight ORMs

There are times when you work with an application which stores data in a light weight /local databases like SQLite etc. You might be looking out for ORM’s that is lightweight and doesnot require lot of configuration to me made . Below is the list of some of the Light Weight ORMs which might help the developers in this scenario. Light Weight ORMs MyBatis jOOQ…

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…

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…

Java – How to declare Hexadecimal literal ?

Problem statement You need to declare an Hexadecimal literal in Java and display the result on a console window. Solution Hexadecimal numbers can contain numbers from 0-9 as well as characters A-F where A-F represents 10-15. You can prefix the numbers with 0X to denote it as hexa decimal number as shown below. The output of the above program will be 10 21

How to Get the localhost IP address in Java ?

If you want to get the localhost IP address in java , you can use the InetAddress class which exposes the getLocalHost method and later use the getHostAddress method of the InetAddress. The getLocalHost method returns the host information of type InetAddress . The InetAddress type has the method getHostAddress which returns the IP address. How to Get the localhost IP address in Java ?…

How to search array elements in Java using Binary Search ?

Do you want to search for an element in a array in Java using Binary Search algorithm ? . If yes , its pretty much easy to do it using the binarySearch method exposed by the Arrays class. How to search array elements in Java using Binary Search ? Below is an example of searching an element using Binary search from array elements in Java.

Java – How to document your code ?

Problem Statement You need to document your java classes so that it helps in maintenance. Solution Use Javadoc and place comments before any method , field or class to document. Just enter /** to start writing the comments using javadoc. The subsequent lines needs to begin with * and end the comment section with */ Below is a sample code demonstrating the usage of the…

Java How to – Get Environment Variables

Problem Statement You need to programmatically get the values of the environment variables from your java program. Solution Use java.lang.System.getenv method to get the environment variables from your java program from Java JDK 1.5 and higher version. You can pass the “PATH” as parameter to the method to retreive the path from the environment variable. When no arguments are passed, it returns all the environment…

Java – How to round a BigDecimal value in Java ?

Problem Statement You need round the BigDecimal value in your Java program. Solution Use the setScale method that is defined in the BigDecimal to round the value of the BigDecimal. You can also set the parameters like BigDecimal.ROUND_HALF_UP etc to the method. Output of the above program is Abundantcode.com Java Tutorials 10102.16