Java Articles

Page 115 of 450

What are annotations in Java?

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 981 Views

Annotations are a tag (metadata) which provides info about a program. Annotations in Java Start with the symbol ‘@’. They are used by the compiler to detect errors. Software tools to generate code. They are used to show attributes of an element: e.g. @Deprecated, @Override. Annotation are used to describe the purpose of an element of the framework, e.g. @Entity, @TestCase, @WebService Annotations describe the behaviour of an element: @Statefull, @Transaction. Example class Sample{ public void display(){ System.out.println(" "); } } public class Test extends ...

Read More

What is static import in Java?

Krantik Chavan
Krantik Chavan
Updated on 11-Mar-2026 835 Views

As import statement allows to use a class without its package qualification, static import allows to access the static members of a class without class qualifications. For Example, to access the static methods you need to call the using class name − Math.sqrt(169); But, using static import you can access the static methods directly. Example import static java.lang.Math.*; public class Sample{ public static void main(String args[]){ System.out.println(sqrt(169)); } } Output 13.0

Read More

What is the keyword used in instantiating a class in Java?

seetha
seetha
Updated on 11-Mar-2026 1K+ Views

An object is created from a class. In Java, the new keyword is used to create new objects. There are three steps when creating an object from a class − Declaration − A variable declaration with a variable name with an object type. Instantiation − The 'new' keyword is used to create the object. Initialization − The 'new' keyword is followed by a call to a constructor. This call initializes the new object. Following is an example of creating an object − Example public class Puppy { public Puppy(String name) { ...

Read More

What is the difference between method hiding and method overriding in Java?

Sreemaha
Sreemaha
Updated on 11-Mar-2026 2K+ Views

When super class and the sub class contains same instance methods including parameters, when called, the super class method is overridden by the method of the sub class. WIn this example super class and sub class have methods with same signature (method name and parameters) and when we try to invoke this method from the sub class the sub class method overrides the method in super class and gets executed. Example class Super{ public void sample(){ System.out.println("Method of the Super class"); } } public class MethodOverriding extends ...

Read More

What is method hiding in Java and how to use it?

Giri Raju
Giri Raju
Updated on 11-Mar-2026 2K+ Views

When super class and sub class contains same method including parameters and if they are static. The method in the super class will be hidden by the one that is in the sub class. This mechanism is known as method hiding. Example class Demo{ public static void demoMethod() { System.out.println("method of super class"); } } public class Sample extends Demo { public static void demoMethod() { System.out.println("method of sub class"); } public static void main(String args[] ) { Sample.demoMethod(); } } Output method of sub class

Read More

Why is method overloading not possible by changing the return type of the method only in java?

mkotla
mkotla
Updated on 11-Mar-2026 3K+ Views

Overloading is the mechanism of binding the method call with the method body dynamically based on the parameters passed to the method call. If you observe the following example, it contains two methods with same name, different parameters and if you call the method by passing two integer values the first method will be executed and, if you call by passing 3 integer values then the second method will be executed.It is not possible to decide to execute which method based on the return type, therefore, overloading is not possible just by changing the return type of the method. Example ...

Read More

How to find numbers in an array that are greater than, less than, or equal to a value in java?

Srinivas Gorla
Srinivas Gorla
Updated on 11-Mar-2026 4K+ Views

You can find numbers in an array that are greater than, less than, or equal to a value as:Examplepublic class GreaterOrLess {    public static void main(String args[]) {       int value = 65;       int[] myArray = {41, 52, 63, 74, 85, 96 };       System.out.println("Elements of the array that are equal to the given value are::");       for(int i = 0; i

Read More

How to convert an array to string in java?

Nikitha N
Nikitha N
Updated on 11-Mar-2026 876 Views

The Arrays class of the java.util package provides toString() methods for all primitive data types and object. These methods accept an array and return its string representation.Therefore, to convert an array to string pass the required array to this method.Exampleimport java.util.Arrays; public class ArrayToString {    public static void main(String args[]) throws Exception {       int[] myArray = {23, 93, 56, 92, 39};       String str = Arrays.toString(myArray);       System.out.println(str);    } }Output[23, 93, 56, 92, 39]

Read More

How to print data of specific element from an array in java?

Monica Mona
Monica Mona
Updated on 11-Mar-2026 15K+ Views

An array is a data structure/container/object that stores a fixed-size sequential collection of elements of the same type. The size/length of the array is determined at the time of creation. The position of the elements in the array is called as index or subscript. The first element of the array is stored at the index 0 and, the second element is at the index 1 and so on. Each element in an array is accessed using an expression which contains the name of the array followed by the index of the required element in square brackets. You can access an ...

Read More

How to create an array of linked lists in java?

Abhinanda Shri
Abhinanda Shri
Updated on 11-Mar-2026 5K+ Views

A linked list is a sequence of data structures, which are connected together via links.To create an array of linked lists, create required linked lists and, create an array of objects with them.Exampleimport java.util.LinkedList; public class ArrayOfLinkedList {    public static void main(String args[]) {       LinkedList list1 = new LinkedList();       list1.add("JavaFX");       list1.add("Hbase");             LinkedList list2 = new LinkedList();       list2.add("OpenCV");       list2.add("Mahout");             LinkedList list3 = new LinkedList();       list3.add("WebGL");       list3.add("CoffeeScript");       Object[] obj = {list1, list2, list3};             for (int i=0; i

Read More
Showing 1141–1150 of 4,498 articles
« Prev 1 113 114 115 116 117 450 Next »
Advertisements