Check if a file is hidden in Java

Samual Sam
Published on 20-Jul-2018 13:50:51
The java.io.File class provides useful methods on file. This example shows how to check a file hidden or not by using the file.isHidden() method of File class.Exampleimport java.io.File; public class Main {    public static void main(String[] args) {       File file = new File("C:/java.txt");     ... Read More

Check if a file exists in Java

karthikeya Boyini
Published on 20-Jul-2018 13:47:06
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()); ... Read More

Character Stream vs Byte Stream in Java

Samual Sam
Published on 20-Jul-2018 13:39:28
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 ... Read More

Chained exception in Java

karthikeya Boyini
Published on 20-Jul-2018 13:29:27
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 ... Read More

Can we override private methods in Java

Samual Sam
Published on 20-Jul-2018 13:21:57
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();   ... Read More

Calling a method using null in Java

karthikeya Boyini
Published on 20-Jul-2018 13:11:18
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 ... Read More

Callback using Interfaces in Java

Samual Sam
Published on 20-Jul-2018 13:06:30
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 ... Read More

Callable and Future in Java

karthikeya Boyini
Published on 20-Jul-2018 12:58:25
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 ... Read More

C/C++ Pointers vs Java references

Samual Sam
Published on 20-Jul-2018 12:48:14
PointersIn C, C++ programming languages, a pointer is a variable that holds the address of another variable.example#include <iostream> using namespace std;   int main() {    //int variable    int i = 8;    //pointer variable    int * pI;    //assign the address of i to its ... Read More

Built-in Exceptions in Java

karthikeya Boyini
Published on 20-Jul-2018 12:24:50
Java defines several exception classes inside the standard package java.lang.The most general of these exceptions are subclasses of the standard type RuntimeException. Since java.lang is implicitly imported into all Java programs, most exceptions derived from RuntimeException are automatically available.Java defines several other types of exceptions that relate to its various class ... Read More
Advertisements