Character Stream vs Byte Stream in Java

Samual Sam
Published on 20-Jul-2018 17:09: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 16:59: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 16:51: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 16:41: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 16:36: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 16:28: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 16:18: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 15:54: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

Bounded types with generics in Java

Samual Sam
Published on 20-Jul-2018 15:40:26
There may be times when you'll want to restrict the kinds of types that are allowed to be passed to a type parameter. For example, a method that operates on numbers might only want to accept instances of Number or its subclasses. This is what bounded type parameters are for.To ... Read More

Blank final in Java

karthikeya Boyini
Published on 20-Jul-2018 15:30:40
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 ... Read More