Program to get yesterday’s date in Java

In this Java program, you will learn how to retrieve yesterday’s date, then print it out to the console. The concept is easy; get today’s date and substrate one day from it. The output will be formatted as MM/DD/YYYY Get yesterday’s Date using Java package cp; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; public class Main … Read more Program to get yesterday’s date in Java

Get IP address, computer name and MAC address using Java

In this code snippet, you will learn how to get an IP Address, computer name, and MAC address in a Windows OS environment using Java. We are going to use the namespaces below in order for this program to execute and run. import java.net.InetAddress; import java.net.NetworkInterface; Java Program to Get IP address, computer name, and … Read more Get IP address, computer name and MAC address using Java

Swapping 2 numbers using Java

This Java example will swap the first variable’s value into the second variable and the second variable’s value into the first variable. Swape two numbers in Java public class Main { public static void main (String args[]) { int num1 = 5, num2 = 10; System.out.println (“Numbers before swapping are:”); System.out.println (“Number 1: ” + … Read more Swapping 2 numbers using Java

Convert hexadecimal string to decimal integer in Java

The program below converts a hexadecimal value to its equivalent in integer. It uses the Integer.parseInt() function to convert from hexadecimal, which is included in the Scanner namespace. Convert Hexadecimal string to an integer using Java import java.util.Scanner; class ConvertHexToInt { public static void main(String args[]) { String hexValue = null; int result = 0; … Read more Convert hexadecimal string to decimal integer in Java

An overview of Input/Output operation in Java (IO)

Streams link is established to a physical layer by a java I/O system to perform input and output operations. Streams are a continuous flow of data. The stream can support all data types, all types of objects, files, and characters to fully execute all input and output operations. Java.io Java.io package contains classes for system … Read more An overview of Input/Output operation in Java (IO)