Displaying directory contents in Java

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 in Java

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

Generating a random number between range in Java

What is random number? A random number is a number that is generated without any predictability or pattern. It is a value that is chosen at random from a set or range of possible values. Random numbers are commonly used in computer programming for various purposes such as generating unique IDs, simulating random events, and … Read more

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 import java.util.Scanner; public class ReverseString { public static void main(String[] args) { Scanner … Read more

Thread stop method in Java

In java, stop()  method  kills/terminates  the currently executing thread. class A extends Thread { public void run() { for (int i = 1; i

Thread Yield method in Java

In java, yield()  method  temporarily pause  the currently executing thread object  and allow other threads to execute. class A extends Thread { public void run() { for (int i = 1; i

Reading a file using FileInputStream

Reading a file using FileInputStream To read a file using FileInputStream in Java, follow these steps: Import the necessary packages: import java.io.FileInputStream; import java.io.IOException; 2. Create a FileInputStream object for the file you want to read: FileInputStream fis = new FileInputStream(“filename.txt”); 3. Create a buffer array to store the data you read from the file: … Read more

Concatenating two strings in Java

The + operator can be used for concatenation of strings. concat(String str) is a method of String class that concatenate two strings and return a String.

Basics of Applet in Java

The Java Applet is a special Java program that are primarily used in a internet programming. Applet program runs on a web browser at client side. Applet program are used to make the web site more dynamic. Applet program embedded in a HTML page and hosted on a web server. Applet Skeleton/ Structure Applet skeleton … Read more

indexof and lastindexof Java Examples

indexOf(int ch) returns int value that is the first occurrence of specified character in given string. Counting start from 0. If character not found it returns -1 indexOf(int ch, int fromIndex) returns int value that is the first occurrence of specified character in given string after specified position. If character not found it returns … Read more