Programming Articles

Page 1583 of 2547

How do I write class names in Java?

usharani
usharani
Updated on 11-Mar-2026 5K+ Views

While writing class names you need to keep the following points in mind. You shouldn’t use predefined or existing class names as the name of the current class. You shouldn’t use any Java keywords as class name (with the same case). The First letter of the class name should be capital and remaining letters should be small (mixed case). class Sample Likewise, first letter of each word in the name should be capital an remaining letters should be small. class Test Keeping interface names simple and descriptive is suggestable. Better not ...

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

How to match a line not containing a word in Java Regex

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 540 Views

Exampleimport java.util.regex.Matcher; import java.util.regex.Pattern; public class NoRegTest {    public static void main(String[] args) {       String s="^fun";       Pattern pattern = Pattern.compile(s);       Matcher matcher = pattern.matcher("Java is fun");       if(!matcher.find()) {          System.out.println("not found");       }    } }Outputnot found

Read More

How do I write variable names in Java?

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

While choosing an identifier to declare a variable in Java you need to keep the following points in mind. The name of the variable should begin with either alphabet or, an underscore (_) or, a dollar ($) sign. The identifiers used for variables must not be keywords. No spaces or special characters are allowed in the variable names of Java. Variable names may contain 0 to 9 numbers (if not at the beginning). Variable names are case sensitive i.e. MY_NUM is different from my_num. If you use two words in a identifier then the you should follow camel case ...

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

Can we overload the main method in Java?

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

Yes, we can overload the main method in Java, but When we execute the class JVM starts execution with public static void main(String[] args) method. Example public class Sample{ public static void main(){ System.out.println("This is the overloaded main method"); } public static void main(String args[]){ Sample obj = new Sample(); obj.main(); } } Output This is the overloaded main method

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

Can you have a method in Java with varying number of arguments?

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

Yes, we can write a method using variable arguments once you use variable arguments as a parameter method while calling you can pass as many numbers of arguments to this method (variable number of arguments) or, you can simply call this method without passing any arguments.Examplepublic class Sample{    void demoMethod(String... args) {       for (String arg : args) {          System.out.println(arg);       }    }    public static void main(String args[] ){       new Sample().demoMethod("ram", "rahim", "robert");       new Sample().demoMethod("krishna", "kasyap");       new Sample().demoMethod();    } }Outputram rahim robert krishna kasyap

Read More

How to convert an array to string in java?

Nikitha N
Nikitha N
Updated on 11-Mar-2026 883 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
Showing 15821–15830 of 25,466 articles
Advertisements