Java exception handling tutorial with example programs
Java exception handling tutorial: In this tutorial we will learn how to handle exception with the help of suitable examples. Exceptions are errors which occur when the program is executing. Consider the Java program below which divides two integ… Read more »
Java constructor tutorial with code examples
Constructor java tutorial: Java constructors are the methods which are used to initialize objects. Constructor method has the same name as that of class, they are called or invoked when an object of class is created… Read more »
Java static method
Java static method program: static methods in Java can be called without creating an object of class. Have you noticed why we write static keyword when defining main it's because program execution begins from main … Read more »
Java static block program
Java programming language offers a block known as static which is executed before main method executes. Below is the simplest example to understand functioning of static block later we see a practical use of static … Read more »
Java methods
Java methods tutorial: Java program consists of one or more classes and a class may contain method(s). A class can do very little without methods. In this tutorial we will learn about Java methods. Methods are… Read more »
How to get input from user in java
This program tells you how to get input from user in a java program. We are using Scanner class to get input from user. This program firstly asks the user to enter a string and then the string is printed, then … Read more »
Java program to print alphabets
This program print alphabets on screen i.e a, b, c, ..., z. Here we print alphabets in lower case. Java source code class Alphabets { public static void main(String args[]) { char ch; for( ch … Read more »
For loop loop program in java
Java for loop used to repeat execution of statement(s) until a certain condition holds true. for is a keyword in Java programming language. Java for loop syntax for (/* Initialization of variables */ ; /*Conditio… Read more »
Java if else program
Java if else program uses if else to execute statement(s) when a condition is fulfilled. Below is a simple program which explains the usage of if else in java programming language. Java programming if else statement // If else in Java code import … Read more »
Bubble sort program in Java
Java program to bubble sort: This code sorts numbers inputted by user using Bubble sort algorithm. Java programming code import java.util.Scanner; class BubbleSort { public static void main(String []args) { int n, c, d, swap; Scanner in… Read more »
Java program to get ip address
This program prints IP or internet protocol address of your computer system. InetAddress class of java.net package is used, getLocalHost method returns InetAddress object which represents local host. Java programming source code import java.net.I… Read more »
Java program to compare two strings
This program compare strings i.e test whether two strings are equal or not, compareTo method of String class is used to test equality of two String class objects. compareTo method is case sensitive i.e "java" and "Java" are two different strings … Read more »
armstrong number program in java
This java program checks if a number is Armstrong or not. Armstrong number is a number which is equal to sum of digits raise to the power total number of digits in the number. Some Armstrong numbers are: 0, 1, 4, 5, 9, 153, 371, 407, 8208 etc. … Read more »