Java public static void main(String[] args)

Shriansh Kumar
Updated on 19-Jun-2025 11:48:14

9K+ Views

The Java program starts execution when the JVM calls the main() method. A Java application begins with this method. Without a main() method, a Java file will compile successfully because at compile time, the compiler doesn't check for a main method, but at run time JVM checks whether the main() method is available or not. Therefore, we will get an exception at run time. In this article, we will understand why we follow the convention "public static void main(String[] args)." The Syntax of a basic Java program looks like: public class class_name { // This line must be ... Read More

Java program for Hexadecimal to Decimal Conversion

Shriansh Kumar
Updated on 19-Jun-2025 10:27:47

1K+ Views

The given task is to write a Java program to convert it into its equivalent decimal number system. The base value of hexadecimal is 16, and decimal is 10. When we convert the hexadecimal to decimal, the base value 16 will be changed to 10. The number system is of four types: Binary, Octal, Decimal, and Hexadecimal. The base value depends on the number of digits contained by the number system. For example, the binary number system contains only two digits, 0 and 1. Hence, its base is 2. Hexadecimal Number System It represents the numbers from 0 to 9 ... Read More

Java Program to Calculate difference between two Time Periods

Shriansh Kumar
Updated on 19-Jun-2025 10:19:22

831 Views

We are given two time periods, and our task is to write a Java program to calculate the difference between them. For this problem, we can use classes and methods of java.time, java.util, and java.text packages. SimpleDateFormat class Date class LocalDate class Period class parse() method between() method As we move further in this article, we will understand the uses of these classes and methods in calculating the difference between two time periods. Some examples ... Read More

Java Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers

Shriansh Kumar
Updated on 19-Jun-2025 10:12:31

1K+ Views

The given task is to write a Java program to check if an integer can be expressed as the sum of two prime numbers. A number is said to be a prime if it has only two factors, which are 1 and itself, and cannot be divided by any other number. Some examples of prime numbers are 2, 3, 5, 7, 11, 13, and so on. 2 is the only even prime number; all other prime numbers are odd numbers. Example Scenario Let's understand the problem with an example. The possible solution is 43 = 2 + 41. Here, 2 and ... Read More

Reverse Words in a String in C++

Ravi Ranjan
Updated on 18-Jun-2025 19:19:54

6K+ Views

In this article, we have a string. Our task is to reverse the words in the given string. Here is an example of reversing the words of a string: Example The example below reverses the words of the given string: Input: "I am Viper" Output: Viper am I Here are the approaches to reverse the words of a string: Using Two Pointer Approach Using STL reverse() Function Using stringstream with Vector Using Recursive Approach ... Read More

C++ Program to Perform Finite State Automaton based Search

Farhan Muhamed
Updated on 18-Jun-2025 19:18:27

889 Views

An automaton with a finite number of states is called a Finite Automaton. We can use a Finite State Automaton (FSA) to perform optimized pattern search operation on a string. This article will discuss how to implement a Finite State Automaton based search in C++. Problem Statement: Given two strings text[] and pattern[], we want to find all occurrences of the pattern in the text using a Finite State Automaton. // Input Strings text[] = "tutorialsPoint provides premium tutorials on various topics" pattern[] = "tutorials" // Output Pattern found at index 0 and 32 Finite State ... Read More

Java Program to Check if two strings are anagram

Shriansh Kumar
Updated on 18-Jun-2025 19:11:41

5K+ Views

An anagram is a word or phrase formed by rearranging the letters of two or more words. Suppose there are two strings. If both strings contain the same set of letters along with the same number of letters, regardless of their order, then we can say that both strings are anagrams; otherwise, not. Now, let's understand how we can find if two strings are anagrams or not in Java. How to Check if two Strings are Anagram? Follow the steps given below to solve the Anagram String problem: ... Read More

Java Nested Loops with Examples

Shriansh Kumar
Updated on 18-Jun-2025 19:09:16

2K+ Views

Loops in Java are called control statements because they decide the flow of execution of a program based on some condition. Java allows the nesting of loops. When we put a loop within another loop, then we call it a nested loop. Nested loops are used when we need to iterate through a matrix array and when we need to do any pattern-based questions. In this article, we are going to learn about Java nested loops with examples. Nested Loops in Java We can create nested loops for the following control statements in Java: ... Read More

Java Program to Reverse a Number

Shriansh Kumar
Updated on 18-Jun-2025 19:05:39

1K+ Views

For a given input number, write a Java program to reverse its digits. In reverse operation, we print the digits of given number from the last to start. The digit at the last position is swapped with the digit at the first position, the second last digit is swapped with second position digit and so on. Example Scenario: Input: number = 123456; Output: rev_number: 654321 How to Reverse a Number in Java? There are multiple ways to reverse the digits of a given number. We are going to discuss the following: Using ... Read More

What will happen if we directly call the run() method in Java?

Vivek Verma
Updated on 18-Jun-2025 19:00:48

283 Views

The run() method of the Thread class is called internally after the start() method is invoked to begin a new thread. However, if the run() method is called directly (without start()), it does not start a separate thread and executes within the current thread. The run() Method In Java, the run() method of the Thread class is used to define the sequence of actions that a thread will execute. This method will be invoked by the Java Virtual Machine (JVM) implicitly; we can also invoke this method explicitly in the current thread without calling the start() method. Note! The run() ... Read More

Advertisements