Java – File Class with Example

Java file Class deals directly with the file and file system. That is, it is the abstract representation of file or directory pathname. It defines the properties of the file itself rather than describing how information is stored in or retrieved from files. File class contains various methods for working with the pathname, deleting and … Read more

Java – Files I/O

Java Input/Output is used for processing input and giving out output. The package java.io contains all the required classes needed for input/output operation. Java uses the term stream for the representation of I/O operation. Stream A stream is a sequence of data. A stream supports many data such as primitives, objects, localized characters, objects, etc. Java’s stream-based … Read more

Java – Applet, Life Cycle of Applet and Methods

The applet in Java is a special type of internet-based program, that runs on the web browser and works at the client-side. It is used to make the webpage more dynamic and provide interactive features that cannot be applied by the HTML alone. Any applet in Java is a class that extends the java.applet.Applet class. … Read more

Java – Exception Handling

An exception in Java is an event that arises during the execution of a program i.e. during run–time. The occurrence of an exception in a program disrupts the normal flow of instructions. This causes the termination of the program or application and therefore needs to be handled by calling an exception handler, which deals with … Read more

Java – Event Handling

Event: An event is an object that describes the change of state in a source. It is the changes made within the GUI(Graphical User Interface). The activities that cause the event to be generated are the pressing of a button, selecting items, input the information, clicking of the mouse, etc, basically all the interaction with … Read more

Java – Deadlock with Example

Deadlock in multithreading is a situation where two or more than two are a lock, waiting for each other. When the first thread needs to use the same lock or wait for the object lock which is acquired by a second thread and the second thread also waits for the lock acquired by a first … Read more

Java – Inter-Thread Communication

When two or more thread needs to exchange information between them in an application, Inter-thread communication is required. Hence, we can also call it Co-Operation. The methods that are used for this communication are: wait() notify() notifyAll() 1. wait() This method is written as: This causes the current thread to wait until another thread invokes … Read more

Java – Static Synchronization

This method is used to achieve static synchronization which locks a class, not an object. Why use static synchronization? Consider a shared class ‘Numbers’ for two objects (obj1 and obj2). The use of the synchronized method and synchronized block cannot interfere between the objects created(th1 and th2 or th3 and th4) for shared class because … Read more

Java – Thread Synchronization

Having multiple threads in a program may cause inconsistency and thread interference, that is the multiple threads when trying to access the same resource. One thread may try to write and another may try to read the shared resource or same file. So to achieve the use of only one resource or file at a … Read more