Raja has Published 469 Articles

Can we declare a top level class as protected or private in Java?

raja

raja

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

8K+ Views

No, we cannot declare a top-level class as private or protected. It can be either public or default (no modifier). If it does not have a modifier, it is supposed to have a default access.Syntax// A top level class    public class TopLevelClassTest {       // Class body }If ... 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

1K+ 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

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

raja

raja

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

284 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

1K+ 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

How to understand StringBuffer is thread-safe and StringBuilder is non-thread-safe in Java?

raja

raja

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

4K+ Views

StringBuffer(Thread-safe)StringBuffer is thread-safe meaning that they have synchronized methods to control access so that only one thread can access StringBuffer object's synchronized code at a time.StringBuffer objects are generally safe to use in a multi-threaded environment where multiple threads may be trying to access the same StringBuffer object at the ... Read More

Can we define a static constructor in Java?

raja

raja

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

5K+ Views

No, we cannot define a static constructor in Java, If we are trying to define a constructor with the static keyword a compile-time error will occur.In general, static means class level. A constructor will be used to assign initial values for the instance variables. Both static and constructor are different ... Read More

How to resize an array in Java?

raja

raja

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

5K+ Views

An array cannot be resized dynamically in Java. One approach is to use java.util.ArrayList(or java.util.Vector) instead of a native array.Another approach is to re-allocate an array with a different size and copy the contents of the old array to the new array.Example:class ResizableArray {    public static void main (String[] args) ... Read More

What are the differences between an Exception class and an Error class in Java?

raja

raja

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

737 Views

Both an Exception class and an Error class are subclasses of java.lang.Throwable class, we can able to handle the exceptions at runtime but the errors we cannot handle.Exceptions are the objects representing the logical errors that occur at the run time and makes JVM enters into the state of "ambiguity".The ... Read More

How to handle the exception using UncaughtExceptionHandler in Java?

raja

raja

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

1K+ Views

The UncaughtExceptionHandler is an interface inside a Thread class. When the main thread is about to terminate due to an uncaught exception the java virtual machine will invoke the thread’s UncaughtExceptionHandler for a chance to perform some error handling like logging the exception to a file or uploading the log to the server before it ... Read More

Advertisements