Java Source Code

Hello world - Starting to learn java program

This is a very simple java program for beginners that demonstrates printing a line of text on the console.

Almost everyone starts learning a new language by writing a Hello World program.
It's one of the simplest program that demonstrates the language syntax and can be easily understood by a beginner.


Taking integer input in Java

This short program demonstrates,how to accept integer inputs from the user and store them in a variable.
Since for taking input from the user,we need to scan the keyboard, we've included the scanner class which has the methods which handle this task for us.
We simply need to use these as shown in the code example below.


Addition of two numbers

This short program demonstrates,how to accept integer inputs from the user and perform arithmetic addition in java.

Like addition, other common arithmetic operations like subtraction,multiplication division,modulo ,etc can be performed in the same manner by using the appropriate symbols for those.


Concatenation of strings in Java

String concatenation in java.
The program demonstrates concatenation of two strings using string class method concat().
The strings can also be concatenated using the "+" operator as shown.


Calculating string length in Java

Program demonstrating use of string methods.

The program demonstrates accepting string from the user and calculating the length using the string class method length().



Generating random numbers/array in Java

Random number generation in java.
This program shows, the method of generation of random numbers in java.
To be able to use the random function,we need to import the random class. The random numbers generated are stored in the array and printed out to the terminal.


Matrix addition in java

Matrix addition in java. This program shows an implementation of matrix addition in java.

The program takes input for the 2D matrix from the user. There is no limit on the matrix size.The user can take any number of rows and columns. The program then checks,if the addition is possible and performs addition if it is valid and prints out the resultant matrix.If the matrix addition is not valid, the program gives an error message.


Matrix subtraction in java

Matrix subtraction in java. This program shows an implementation of matrix subtraction in java.

The program takes input for the 2D matrix from the user. There is no limit on the matrix size.The user can take any number of rows and columns. The program then checks,if the subtraction is possible and performs subtraction if it is valid and prints out the resultant matrix.If the matrix subtraction is not valid, the program gives an error message.