Karthikeya Boyini has Published 2383 Articles

Compound assignment operators in Java

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2020 14:44:15

1K+ Views

The Assignment OperatorsFollowing are the assignment operators supported by Java language −OperatorDescriptionExample=Simple assignment operator. Assigns values from right side operands to left side operand.C = A + B will assign value of A + B into C+=Add AND assignment operator. It adds right operand to the left operand and assigns ... Read More

Chained exception in Java

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2020 13:30:06

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 ... Read More

Check if a file exists in Java

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2020 13:22:20

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()); ... Read More

Checked vs Unchecked exceptions in Java

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2020 13:13:42

7K+ Views

Checked exceptionsA checked exception is an exception that occurs at the compile time, these are also called as compile time exceptions. These exceptions cannot simply be ignored at the time of compilation, the programmer should take care of (handle) these exceptions.For example, if you use FileReader class in your program ... Read More

clone() method in Java

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2020 13:04:31

782 Views

Java provides an assignment operator to copy the values but no operator to copy the object. Object class has a clone method which can be used to copy the values of an object without any side-effect. Assignment operator has a side-effect that when a reference is assigned to another reference ... Read More

Blank final in Java

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2020 12:40:21

604 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 ... Read More

Callable and Future in Java

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2020 12:31:29

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 ... Read More

Calling a method using null in Java

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2020 12:27:06

529 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 ... Read More

Addition and Concatenation in Java

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2020 09:33:21

1K+ Views

'+' operator in java can be used to add numbers and concatenate strings. Following rules should be considered.Only numbers as operands then result will be a number.Only strings as operands then result will be a concatenated string.If both numbers and strings as operands, then numbers coming before string will be ... Read More

Array Declarations in Java

karthikeya Boyini

karthikeya Boyini

Updated on 18-Jun-2020 09:24:40

723 Views

Here is the syntax for declaring an array variable −SyntaxdataType[] arrayRefVar;   // preferred way. or dataType arrayRefVar[];  // works but not preferred way.Note − The style dataType[] arrayRefVar is preferred. The style dataType arrayRefVar[] comes from the C/C++ language and was adopted in Java to accommodate C/C++ programmers.ExampleThe following ... Read More

Advertisements