Raja has Published 806 Answers

What are the differences between tight coupling and loose coupling in Java?

raja

raja

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

Tight coupling means classes and objects are dependent on one another. In general, tight coupling is usually not good because it reduces the flexibility and re-usability of the code while Loose coupling means reducing the dependencies of a class that uses the different class directly.Tight CouplingThe tightly coupled object is ... Read More

What is the contract between equals() and hashCode() methods in Java?

raja

raja

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

Every Java object has two very important methods equals() and hashCode() and these methods are designed to be overridden according to their specific general contract. An Object class is the parent class of every class, the default implementation of these two methods is already present in each class. However, we can ... Read More

Why Char[] array is more secure (store sensitive data) than String in Java?

raja

raja

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

Both String and Char[] array are used to store the textual data but choosing one over the other is more difficult. Maybe we can get the idea from the immutability of String why char[] array is preferred over String for storing sensitive information data like password, SSN,  etc.Using the plain string is ... Read More

What are unreachable catch blocks in Java?

raja

raja

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

A block of statements to which the control can never reach under any case can be called as unreachable blocks. Unreachable blocks are not supported by Java. The catch block mentioned with the reference of Exception class should and must be always last catch block because Exception is the superclass of ... Read More

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

raja

raja

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

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

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

What is a constant and how to define constants in Java?

raja

raja

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

A constant is a variable whose value cannot change once it has been assigned. Java doesn't have built-in support for constants.A constant can make our program more easily read and understood by others. In addition, a constant is cached by the JVM as well as our application, so using a ... Read More

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

raja

raja

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

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

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

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

Advertisements