Raja has Published 760 Articles

What are the differences between compareTo() and compare() methods in Java?

raja

raja

Updated on 06-Feb-2020 11:40:17

6K+ Views

The Comparable interface provides a compareTo() method for the ordering of objects. This ordering is called the class’s natural ordering and the compareTo() method is called its natural comparison method. The Comparator interface provides the methods for performing sorting operations. By using the Comparator interface we can do multiple sorting sequences. We can sort the objects ... Read More

Can we declare more than one class in a single Java program?

raja

raja

Updated on 06-Feb-2020 11:35:52

13K+ Views

A single Java program contains two or more classes, it is possible in two ways in Java.Two Ways of Implementing Multiple Classes in a single Java ProgramNested ClassesMultiple non-nested classesHow the compiler behave with Multiple non-nested classesIn the below example, the java program contains two classes, one class name is ... Read More

Can we create an object of an abstract class in Java?

raja

raja

Updated on 06-Feb-2020 11:32:30

12K+ Views

No, we can't create an object of an abstract class. But we can create a reference variable of an abstract class. The reference variable is used to refer to the objects of derived classes (subclasses of abstract class).An abstract class means hiding the implementation and showing the function definition to ... Read More

What is the importance of the Throwable class and its methods in Java?

raja

raja

Updated on 06-Feb-2020 11:30:26

345 Views

The Throwable class is a superclass of all errors and exceptions in Java. Objects that are instances of this class are thrown by the Java Virtual Machine or can be thrown by a throw statement. Similarly, this class or one of its subclasses can be the argument type in a catch clause.Instances of ... Read More

Can we declare the main () method as final in Java?

raja

raja

Updated on 06-Feb-2020 11:11:06

4K+ Views

Yes, we can declare the main () method as final in Java. The compiler does not throw any error.If we declare any method as final by placing the final keyword then that method becomes the final method.The main use of the final method in Java is they are not overridden.We can not ... Read More

What are the different types of classes in Java?

raja

raja

Updated on 06-Feb-2020 11:06:17

2K+ Views

Types of classes in JavaConcrete classAny normal class which does not have any abstract method or a class that has an implementation of all the methods of its parent class or interface and its own methods is a concrete class.ExampleLive Demopublic class Concrete { // Concrete Class    static int ... Read More

What are the differences between default constructor and parameterized constructor in Java?

raja

raja

Updated on 06-Feb-2020 11:01:46

10K+ Views

Default ConstructorA default constructor is a 0 argument constructor which contains a no-argument call to the super class constructor.To assign default values to the newly created objects is the main responsibility of default constructor.Compiler writes a default constructor in the code only if the program does not write any constructor in ... Read More

Why we should follow the naming conventions in Java?

raja

raja

Updated on 06-Feb-2020 11:00:02

3K+ Views

Naming conventions in Java make programs more understandable by making them easier to read.In Java, class names generally should be nouns, in title case with the first letter of each separate word capitalized. and interface names generally should be adjectives,  in title case with the first letter of each separate ... Read More

How many ways to prevent method overriding in Java?

raja

raja

Updated on 06-Feb-2020 10:57:24

3K+ Views

Method overriding works because of the run-time method binding feature in Java. So, if we force the java compiler to do static binding for a method then we can prevent that method from being overridden in a derived class.We can prevent method overriding in Java in 3 waysBy making method ... Read More

Why AWT components are heavy-weight while Swing components are light-weight in Java?

raja

raja

Updated on 06-Feb-2020 10:46:30

1K+ Views

AWT stands for Abstract Window ToolKit and it supports Java GUI programming. It is a portable GUI library for Stand-alone Java applications/applets. The AWT provides the connection between our application and the native GUI while Java Swing implements a set of GUI components that build on AWT technology and it can ... Read More

Advertisements