Raja has Published 760 Articles

Can we declare a try catch block within another try catch block in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

8K+ Views

Yes, we can declare a try-catch block within another try-catch block, this is called nested try-catch block.Nested Try-Catch BlockIf an inner try statement does not have a matching catch statement for a particular exception, the control is transferred to the next try statement catch handlers that are expected for a matching ... Read More

What are the differences between length and length () in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

3K+ Views

The length is an instance variable of an array in Java whereas length() is a method of String class.lengthAn array is an object that holds a fixed number of values of the same type.The length variable in an array returns the length of an array i.e. a number of elements ... Read More

What is Double-buffering in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

2K+ Views

Double-buffering is the process of drawing graphics into an off-screen image buffer and then copying the contents of the buffer to the screen all at once.For the complex graphics, using double-buffering can reduce flickering issues.Java Swing automatically supports double-buffering for all of its components.Double-buffering is memory intensive, its use is ... Read More

What are the different types of nested classes are defined in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

769 Views

In Java, it is possible to define a class inside another class, such classes are called Nested classes. We can use the access modifiers like private, public, protected or default for inner classes and default or public access modifiers for outer class.There are two types of nested classes are defined in ... Read More

What is a ClassCastException and when it will be thrown in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

1K+ Views

The java.lang.ClassCastException is one of the unchecked exception in Java. It can occur in our program when we tried to convert an object of one class type into an object of another class type.When will be ClassCastException is thrownWhen we try to cast an object of Parent class to its Child class type, this exception ... Read More

What will happen when we try to override final method of the superclass in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

1K+ Views

Any method that is declared as final in the superclass cannot be overridden by a subclass. If we try to override the final method of super class we will get an error in Java.Rules for implementing Method OverridingThe method declaration should be the same as that of the method that is to be ... Read More

Can we declare a constructor as private in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

9K+ Views

Yes, we can declare a constructor as private. If we declare a constructor as private we are not able to create an object of a class. We can use this private constructor in the Singleton Design Pattern.Conditions for Private ConstructorA private constructor does not allow a class to be subclassed.A private ... Read More

Can we define a method name same as class name in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

4K+ Views

Yes, It is allowed to define a method with the same name as that of a class. There is no compile-time or runtime error will occur. But this is not recommended as per coding standards in Java. Normally the constructor name and class name always the same in Java.ExampleLive Demopublic class ... Read More

Where to use a StringBuffer/StringBuilder than a String in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

185 Views

The String class objects are immutable whereas the StringBuffer and the StringBuilder objects are mutable.A StringBuffer is synchronized while a StringBuilder is not synchronized.A Concatenation operator "+" is internally implemented using either StringBuffer or StringBuilder.If the Object value is not going to change use String Class because a String object ... Read More

How to make a class thread-safe in Java?

raja

raja

Updated on 30-Jul-2019 22:30:26

634 Views

A thread-safe class is a class that guarantees the internal state of the class as well as returned values from methods, are correct while invoked concurrently from multiple threads.The HashMap is a non-synchronized collection class. If we need to perform thread-safe operations on it then we must need to synchronize ... Read More

Advertisements