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 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 »
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 »
Factorial program in java
import java.util.Scanner; class Factorial{ public static void main(String args[]) { int n, c, fact = 1; System.out.println("Enter an integer to calculate it's factorial"); Scanner in = new Scanner(System.in); n = in.nextInt()… Read more »
Palindrome program in java
import java.util.*; class Palindrome { public static void main(String args[]) { String original, reverse=""; Scanner in = new Scanner(System.in); System.out.print("Enter a string : "); original = in.nextLine(); in… Read more »
Calculator program in java
import java.util.Scanner; import java.io.*; public class Calculator { public static void main(String[] args) { int choice; int x = 0; int y = 0; int sum; PrintStream out; Scanner… Read more »