![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9326 Articles for Object Oriented Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
5K+ Views
The java.io.File class provides useful methods on file. This example shows how to check a file existence by using the file.exists() method of File class.Exampleimport java.io.File; public class Main { public static void main(String[] args) { File file = new File("C:/java.txt"); System.out.println(file.exists()); } }ResultThe above code sample will produce the following result (if the file "java.txt" exists in 'C' drive).trueExampleThe following is another simple example of the file exist or not in java.import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintpWriter; import java.nio.file.FileAlreadyExistsException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
8K+ Views
Byte StreamsJava byte streams are used to perform input and output of 8-bit bytes. Though there are many classes related to byte streams but the most frequently used classes are, FileInputStream and FileOutputStream. Following is an example which makes use of these two classes to copy an input file into an output file −Exampleimport java.io.*; public class CopyFile { public static void main(String args[]) throws IOException { FileInputStream in = null; FileOutputStream out = null; try { in = new ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
Chained exception helps to relate one exception to other. Often we need to throw a custom exception and want to keep the details of an original exception that in such scenarios we can use the chained exception mechanism. Consider the following example, where we are throwing a custom exception while keeping the message of the original exception.ExampleLive Demopublic class Tester { public static void main(String[] args) { try { test(); }catch(ApplicationException e) { System.out.println(e.getMessage()); } } ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
957 Views
Ideally No. But, using the tricky code, a subclass can override a private method as well. See the example below −ExampleLive Democlass A { private void display() { System.out.println("A.display"); } public void callDisplay() { System.out.println("A.callDisplay"); display(); } } class B extends A { private void display() { System.out.println("B.display"); } public void callDisplay() { System.out.println("B.callDisplay"); display(); } } public class Tester { public static void main(String[] args) { ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
525 Views
When a method is invoked on a null reference, it throws NullPointerException but in case of the static method, we can make it possible using cast expression. See the example below −ExampleLive Demopublic class Tester { public static void display(){ System.out.println("display"); } private void print() { System.out.println("print"); } public static void main(String[] args) { //Scenario 1: //Calling a method on null reference //causes NullPointerException try { Tester test = null; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
3K+ Views
In the case of Event-driven programming, we pass a reference to a function which will get called when an event occurs. This mechanism is termed as a callback. Java does not support function pointers. So we can not implement the same direction. But using interfaces we can achieve the same very easily.In the example below, we've made a callback when a button is clicked. See the steps −Create an interface ClickEventHandler with a single method handleClick().Create a ClickHandler class which implements this interface ClickEventHandler.Create a Button class which will call ClickHandler when it's click method is called.Test the application.ExampleLive Demo//Step ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
3K+ Views
java.util.concurrent.The callable object can return the computed result done by a thread in contrast to a runnable interface which can only run the thread. The Callable object returns a Future object which provides methods to monitor the progress of a task being executed by a thread. The future object can be used to check the status of a Callable and then retrieve the result from the Callable once the thread is done. It also provides timeout functionality.Syntax//submit the callable using ThreadExecutor //and get the result as a Future object Future result10 = executor.submit(new FactorialService(10)); //get the result using ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
598 Views
In Java, a final variable can a be assigned only once. It can be assigned during declaration or at a later stage. A final variable if not assigned any value is treated as a blank final variable. Following are the rules governing initialization of a blank final variable.A blank instance level final variable cannot be left uninitialized.The blank Instance level final variable must be initialized in each constructor.The blank Instance level final variable cannot be initialized in class methods.A blank static final variable cannot be left uninitialized.The static final variable must be initialized in a static block.A static final variable cannot ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
14K+ Views
Java supports two types of right shift operators. The >> operator is a signed right shift operator and >>> is an unsigned right shift operator. The left operands value is moved right by the number of bits specified by the right operand.Signed right shift operatorThe signed right shift operator '>>' uses the sign bit to fill the trailing positions. For example, if the number is positive then 0 will be used to fill the trailing positions and if the number is negative then 1 will be used to fill the trailing positions.Assume if a = 60 and b = -60; ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
611 Views
automatic resource management or try-with-resources is a new exception handling mechanism that was introduced in Java 7, which automatically closes the resources used within the try-catch block.ResourceA resource is an object which is required to be closed once our program finishes. For example, a file is read, database connection and so on.UsageTo use the try-with-resources statement, you simply need to declare the required resources within the parenthesis, and the created resource will be closed automatically at the end of the block. Following is the syntax of the try-with-resources statement.Syntaxtry(FileReader fr = new FileReader("file path")) { // use the resource ... Read More