Tag: Java

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

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

Developing a Java program – Hello World

There are lot of IDE options for the developers to create a java application . In this article , we will use Jet brains IntelliJ IDEA Community edition of the IDE to develop the Java console application. Developing Java program in IntelliJ IDEA 1. Download and install Jet brains IntelliJ IDEA Community edition . Make sure you have the Java (JDK) installed on your PC…