If a class is declared without any access modifiers, where may the class be accessed

A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package. If a class in Java is declared without any access modifiers, it will have package-private (also known as default) … Read more

What classes of exceptions may be caught by a catch clause

A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types. In Core Java, catch clauses are used to handle exceptions. There are three types of exceptions in Java, and a catch clause can catch and handle exceptions of these types: Checked Exceptions (or … Read more

What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy

The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented. The main difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy in Java is the type of data they handle. Byte-oriented Streams (InputStream and OutputStream): These classes deal with raw binary data in the form of bytes. InputStream is used for reading byte-oriented data. … Read more

What happens when a thread cannot acquire a lock on an object

If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object’s lock, it enters the waiting state until the lock becomes available. In Java, when a thread attempts to acquire a lock on an object using the synchronized keyword or by using the Lock interface, and it … Read more

How is rounding performed under integer division

The fractional part of the result is truncated. This is known as rounding toward zero. In Java, rounding is performed towards zero under integer division. This means that the fractional part is simply truncated, and the result is the integer quotient without rounding up or down. For example, consider the following division: java int result … Read more