Karthikeya Boyini has Published 2382 Articles

What is the difference between checked and unchecked exceptions in Java?

karthikeya Boyini

karthikeya Boyini

Updated on 25-Feb-2020 10:45:28

724 Views

A 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.ExampleIf you use FileReader class in your program to read data ... Read More

What does the method fill(obj[], int fromIndex, int toIndex, int val) do in java?

karthikeya Boyini

karthikeya Boyini

Updated on 25-Feb-2020 08:21:52

80 Views

The fill(object[] a, int fromIndex, int toIndex, object val) method of the class java.util.Arrays assign the specified Object reference to each element of the specified range of the specified array of objects. The range to be filled extends from index fromIndex, inclusive, to index toIndex, exclusive. (If fromIndex==toIndex, the range to be ... Read More

What does the method sort(int[] a, int fromIndex, int toIndex) do in java?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Feb-2020 12:33:49

63 Views

The sort(int[] a, int fromIndex, int toIndex) method of the java.util.Arrays class sorts the specified range of the specified array of integer value into ascending numerical order. The range to be sorted extends from index fromIndex, inclusive, to index toIndex, exclusive.Exampleimport java.util.Arrays; public class ArrayDemo {    public static void ... Read More

What is the type conversion operator ( ) in Java and how to use it?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Feb-2020 10:09:52

814 Views

Cast operator in java is used to convert one data type to other.Examplepublic class Sample {    public static void main(String args[]) {       double d = 20.3;       int i = (int)d;       System.out.println(i);    } }Output20

How to perform sort using Java?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Feb-2020 09:52:19

74 Views

You can sort an array using sort() method of the Arrays class.ExampleLive Demoimport java.util.Arrays; public class MainClass {    public static void main(String args[]) throws Exception {       int array[] = { 2, 5, -2, 6, -3, 8, 0, -7, -9, 4 };       Arrays.sort(array);   ... Read More

How to list all files in a directory using Java?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Feb-2020 08:21:45

773 Views

You can get the list of files in a directory −Create a directory object using the File class.Get the list of directories in it using the getName() method.Exampleimport java.io.File; public class FindingDirectories {    public static void main(String args[]) {       String dir ="C:/Users/Tutorialspoint/Desktop/movies";       ... Read More

How to capture file not found exception in Java?

karthikeya Boyini

karthikeya Boyini

Updated on 20-Feb-2020 06:58:29

291 Views

While using FileInputStream, FileOutputStream, and RandomAccessFile classes, we need to pass the path of the file to their constructors. In case of a file in the specified path does not exist a FileNotFoundException is raised.Examplepublic class Sample {    public static void main(String args[]) throws Exception {       ... Read More

How do I declare and initialize an array in Java?

karthikeya Boyini

karthikeya Boyini

Updated on 19-Feb-2020 10:06:11

384 Views

You can declare an array just like a variable −int myArray[];You can create an array just like an object using the new keyword −myArray = new int[5];You can initialize the array by assigning values to all the elements one by one using the index −myArray [0] = 101; myArray [1] ... Read More

How to access the private methods of a class from outside of the class in Java?

karthikeya Boyini

karthikeya Boyini

Updated on 18-Feb-2020 10:00:48

5K+ Views

You can access the private methods of a class using java reflection package.Step1 − Instantiate the Method class of the java.lang.reflect package by passing the method name of the method which is declared private.Step2 − Set the method accessible by passing value true to the setAccessible() method.Step3 − Finally, invoke the method ... Read More

What are up-casting and down-casting in Java?

karthikeya Boyini

karthikeya Boyini

Updated on 18-Feb-2020 09:57:00

1K+ Views

Typecasting is converting one data type to another.Up-casting − Converting a subclass type to a superclass type is known as up casting.Exampleclass Super {    void Sample() {       System.out.println("method of super class");    } } public class Sub extends Super {    void Sample() {   ... Read More

Advertisements