Java Articles

Page 139 of 450

Importance of return type in Java?

Vivek Verma
Vivek Verma
Updated on 29-May-2025 27K+ Views

A method in Java is a set of statements that can be reused in the program whenever we want. We can write a method once and call it multiple times. We can return values from a method; the datatype of the value we return is known as the return type.  We return values from a Java method using a return statement. A return statement causes the program control to transfer back to the caller of a method. Every method in Java is declared with a return type, ...

Read More

How To Check Whether a Number Is a Pronic Number or Not in Java?

Vivek Verma
Vivek Verma
Updated on 29-May-2025 7K+ Views

What is Pronic number? In mathematical terms, a Pronic number is a number that can be defined as the product of two consecutive integers. The Pronic number is in the form of n(n+1), where n is the integer. For example, the pronic numbers are 0, 2, 6, 12, 20, and so on. It is also known asa heteromecic number, oblong number, or rectangular number. Input & Output Scenarios Following are the scenarios that show the mathematical calculation for checking of the pronic number: Scenario 1 Suppose we have a number 12: Input: 12 Output: 4 x 3 = ...

Read More

How To Check If Three Points are Collinear in Java?

Vivek Verma
Vivek Verma
Updated on 29-May-2025 2K+ Views

In mathematical terms, three points are said to be collinear if all three points lie on a straight line. If the points do not lie on the same straight line, then they are not considered collinear points. Those three points represent coordinates on a plane: (x1, y1), (x2, y2), and (x3, y3). They must lie on the same straight line to be considered collinear. Where, x1, y1, x2, y2, x3, y3 are the points on x and y axis and (x1, y1), (x2, y2), (x3, y3) are the coordinates.Determining Colinearity Mathematically, there are two ways to know whether the three points ...

Read More

What can cause the \\\"cannot find symbol\\\" error in Java?

Vivek Verma
Vivek Verma
Updated on 29-May-2025 12K+ Views

In Java, the cannot find symbol error occurs when we try to reference a variable that is not declared in the program or when we try to access a class that is not declared or imported.  Possible Causes of 'Cannot Find Symbol' Error Below is a list of some possible causes of the 'cannot find symbol' error in Java - Using a variable that is not declared or outside the code. Using wrong cases ("tutorials" and "Tutorials" are different) or making spelling mistakes. The packaged class has ...

Read More

How to create a thread by using anonymous class in Java?

Vivek Verma
Vivek Verma
Updated on 27-May-2025 4K+ Views

This article will use an anonymous class to create a Thread in Java. An Anonymous class is a class that does not have a name. Thread in Java In Java, a Thread is a part of a program that can be executed independently. All Java programs have at least one thread, known as the main thread, which is created by the Java Virtual Machine (JVM), when the main() method is invoked. Creating a Thread by Using Anonymous Class In Java, the basic way to create a thread is to either extend the Thread class or implement the Runnable interface. However, we ...

Read More

What is the use of Object Cloning in Java?

Vivek Verma
Vivek Verma
Updated on 27-May-2025 2K+ Views

The article will explain the use of object cloning in Java and provide an appropriate example to clarify the problem. What is the Object Cloning in Java? In Java, object cloning is a way to create an exact copy of an object. We can use the clone() method provided by the Object class to create a clone of an object. When an object is cloned, a new instance of the same class is created, and the fields of the original object are copied to the new object. The Cloneable interface must be implemented by a class whose object is ...

Read More

How many ways to call garbage collector (GC) in Java?\\n

Vivek Verma
Vivek Verma
Updated on 27-May-2025 2K+ Views

This article explains the different ways of calling the garbage collector (GC) in Java. It also includes a brief introduction to garbage collection, various calling approaches, and relevant examples. Garbage Collection (GC) in Java In Java, the garbage collection is carried out by a daemon thread called the Garbage Collector (GC). Instead of waiting until the Java Virtual Machine (JVM) runs a garbage collector, we can request the JVM to run the garbage collector. There is no guarantee that the JVM will accept our request. In Java, we can call the garbage collector (GC) manually in "two ways", which ...

Read More

How to convert between List and Array in Java?

Vivek Verma
Vivek Verma
Updated on 27-May-2025 1K+ Views

In Java, a List is an interface that represents an ordered collection of elements of the same type. You cannot directly create an object of the List interface, instead, you need to instantiate an ArrayList class or another class that implements the List interface.An array is a container that holds a fixed size of similar types of data. As the size is fixed, it can not be changed once created.The conversion between List and array is important because array provides faster access to the elements than List interface (faster in case of searching elements), and provides a fixed size of ...

Read More

How To Check if a Triangle is Valid or Not When Sides are Given in Java?

Vivek Verma
Vivek Verma
Updated on 27-May-2025 9K+ Views

A Triangle is a polygon that has 3 sides, and it consists of three sides and three vertices. The sum of the three internal angles is up to 180 degrees. Below is the diagram of a triangle having three sides (a, b, and c): In a valid triangle, if you add any two sides, then it will be greater than the third side. As per our problem statement, we have to check if a triangle is valid or not, if three sides are given, using the Java programming language. Suppose a, b and c are the three sides of ...

Read More

How to handle the ArithmeticException (unchecked) in Java?\\n

Shriansh Kumar
Shriansh Kumar
Updated on 27-May-2025 7K+ Views

Java ArithmeticException The ArithmeticException of java.lang package is an unchecked exception in Java. It is raised when an attempt is made to use a wrong mathematical expression in the Java program. An example of ArithmeticExeption is division by 0. If you divide two numbers and the number in the denominator is zero. The Java Virtual Machine will throw ArithmeticException. Example: Throwing ArithmeticException In the following Java program, we try a mathematical operation where we divide a number by 0. public class ArithmeticExceptionTest { public static void main(String[] args) { int a ...

Read More
Showing 1381–1390 of 4,496 articles
« Prev 1 137 138 139 140 141 450 Next »
Advertisements