DataInputStream and DataOutputStream for primitive data

In java, a basic input-output stream provides a method for reading & writing bytes or characters in a file. If we want to read-write primitive data types (such as int, float, etc.) then we can use filter classes to filter data in the original stream. DataInputStream & DataOutputStream are two filter classes used for creating … Read more

Leap Year Program in Java

A Leap Year is a year which has 366 days. This year February is of 29 days. Leap years occurs in every four years. A leap year has following constraints. We can check in programming as below A year is divisible by 400 then it is a leap year A year is divisible by 4 … Read more

What is Java Pi | Pi in Java | Math.PI Java Value and Example

Pi (π) is a well-known mathematical constant whose value is 22/7 or 3.14159265359. Programming languages also use this constant for mathematical calculation. Here we discuss PI with respect to the Java programming language. In Java PI is defined as a field in java.lang.Math class. It is defined as static double PI and described as The double value … Read more

Date to Timestamp conversion

To convert java.util.Date to java.sql.TimeStamp as given below

String matching and comparing in Java

equals(Object anObject) compare String with object and returns boolean value, for comparing two strings if both are strictly equals(case sensitive) then it will return true else false value. equalsIgnoreCase(String anotherString) compare two strings with case ignorance and return boolean value. compareTo(String anotherString) compare two strings and return int value if both are equal(with case) … Read more

Displaying directory contents

For listing a directory content in java we use File class and use isDirectory() method to check whether it is directory or not. if directory then we use listFiles().

Converting given string to upper and lower case

toUpperCase() and toLowerCase() are methods in String class which converts given string in upper and lower case respectively and return a string.

Java program to swap two numbers

1 Swapping two numbers using third variable

Output

2. Swapping two numbers without using third variable

Output

3. Swapping two numbers in a single line using addition and subtraction

Output

4. Swapping two numbers in a single line using multiplication and division

Output

5. Swapping two numbers … Read more

Generating a random number between range in Java

To generate random numbers java users Random class and to generate integer random number nextInt(maxNo) of Random number is used the parameter maxNo specifies that this method generate a integer number between 0 and maxNo.

It will generate random number between 0 and 100, where 0 and 100 are included

Write a java program to reverse a string

We are discussing java program to reverse a string using following ways Java program to reverse a string using StringBuffer or StringBuilder class Java program to reverse a string using Loops(Iteration) Java program to reverse a string using StringBuffer or StringBuilder class

Output

Java program to reverse a string using Loops(Iteration) Copy and … Read more