Exception Handling in Java with Examples

To learn about exception handling first you must know what is an exception What is an Exception in Java An exception is run time error that can occur due to wrong user input or due to logical error in programming. Arithmetic Exception Example Consider a simple example. Take two integer number from command prompt and … Read more

How to get the length of the 2D array in Java

Two dimensional array in java To declare an 2D array in java we use the following syntax Datatype [][] arrayName=new Datatype[rows][cols] If you want to declare any primitive 2D array. int [][] ages=new int[3][4]; double [][] prices=new double[4][4] Array ages is a two-dimensional int array, it can store 3 rows and each row can contain … Read more

Print prime numbers from 1 to n in java

Print prime numbers from 1 to n in java using while loop

Read More Prime Number Program In Java Using While Loop

Exception Handling try catch finally blocks in Java

What is try block A try block is used to surround a set of statements where exceptions may occur. A try block used with catch and finally block Also Read Exception Handling in Java: Hierarchy Example and Types What is a catch block A catch block is created followed by a try block. Whenever an … Read more

Throw and Throws Keywords in Java

In java programming, If the exception occurs within the try block it is thrown. Throw and Throws Keywords in Java is very important to throw exceptions. a throw keyword is used to throw an exception A system-generated exception is automatically thrown by the java run time system but if we want to manually throw an … Read more

Java Scanner Class Getting Input from user and file

Java Scanner class is used to take input from users and file. Scanner class is defined as java.util.Scanner It is defined as a final class and extends the Object class and implements Iterator<String> and Closeable interface.

Scanner class reads data in form of tokens and break token based on the delimiter the default delimiter … Read more

Methods in Java-how to call a method in java

Introducing Method In java programming language classes usually consist of two things instance variable and methods. What is a method in java                                                                  A method is the block of statements that performs a special task. Using methods we can avoid rewriting the same code over and over in a sane program. The method increases the … Read more

Checking whether a file or directory in Java

Checking whether the File object exists if exists then check whether it is file of directory to check file existance exists() method of File class is used if it returns true means file or directory exists, at this point we are not confirm existing File object is file or directory. To check file object isDirectory() … Read more

Harshad numbers

In this universe, we know that the number system is the base of every mathematical model. When we talk about programming, we do deal with numbers and a way to manipulate the data variables through in-built functions and modules. Lots of concepts are there from which one is a Harshad Number. Another name of Harshad … Read more

Thread Life Cycle in Java

Thread Life Cycle in Java tells the various information of thread form born to terminate. Thread life cycle contains the several stages and at a time any thread can be present  in a single state. States of Thread life cycle Born Ready Running Blocked Sleep Wait Dead Ready:  In this state thread is ready to … Read more