Found 593 Articles for Java Programming

What is the object class in Java?

Syed Javed
Updated on 30-Jul-2019 22:30:22
The java.lang.Object class is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class. Example Following example demonstrates the usage of the Object class. Here we are getting the name of the current class using the getClass() method. Live Demo import java.util.GregorianCalendar; public class ObjectDemo { public static void main(String[] args) { //Create a new ObjectDemo object GregorianCalendar cal = new GregorianCalendar(); ... Read More

What is the character wrapper class and its methods in Java?

Syed Javed
Updated on 30-Jul-2019 22:30:22
The Character class of the java.lang package wraps a value of the primitive datatype char. It offers a number of useful class (i.e., static) methods for manipulating characters. You can create a Character object with the Character constructor. Character ch = new Character('a'); Following are the notable methods of the Character class. 1 isLetter() Determines whether the specified char value is a letter. 2 isDigit() Determines whether the specified char value is a digit. 3 isWhitespace() Determines whether the specified char value is white space. 4 isUpperCase() Determines ... Read More

Can a method have the same name as the class?

Syed Javed
Updated on 30-Jul-2019 22:30:22
Yes, you can write a method in Java with method name same as class name. But it is not suggestable because of the following reasons − Using upper case letter at the starting of the name of the method violates the coding conventions of Java for writing a methods name. There is a chance of assuming such methods with constructors of the class. Example Live Demo public class Sample { public void Sample(){ System.out.println("This is a sample method"); } public static void main(String args[]){ Sample obj = new Sample(); obj.Sample(); } } Output This is a sample method
Advertisements