Category: Java programs

python tutorials and learn python

Created with Sketch.

Java program to generate random numbers

  Java program to generate random numbers Java program to generate random numbers. We print 10 random numbers in the range [0, 100]. Program to generate random numbers in Java import java.util.*; class RandomNumbers { public static void main(String[] args) { int c; Random t = new Random(); // random integers in [0, 100] for…
Read more

Garbage collection in Java

  Garbage collection in Java Java program to perform garbage collection: Free memory in Java virtual machine is printed, and then garbage collection is done using the gc method of RunTime class, freeMemory method returns the amount of free memory in JVM, getRunTime method is used to get the reference of current RunTime object. Garbage…
Read more

Java program to get IP address

  Java program to get IP address Java program to print the IP (Internet Protocol) address of a computer system, we use InetAddress class of java.net package, the getLocalHost method returns InetAddress object, which represents the localhost. Java IP address program import java.net.InetAddress; class IPAddress { public static void main(String args[]) throws Exception { System.out.println(InetAddress.getLocalHost());…
Read more

Reverse a number in Java

  Reverse a number in Java Java program to find the reverse of a number, for example, if the input is 951, the output is 159. Java program to reverse a number import java.util.Scanner; class ReverseNumber { public static void main(String args[]) { int n, reverse = 0; System.out.println(“Enter an integer to reverse”); Scanner in…
Read more

Matrix addition in Java

  Matrix addition in Java Java program to add two matrices of any order. You can modify it to add any number of matrices. Addition of two matrix in Java import java.util.Scanner; class AddTwoMatrix { public static void main(String args[]) { int m, n, c, d; Scanner in = new Scanner(System.in); System.out.println(“Enter the number of…
Read more

Transpose of a matrix in Java

  Transpose of a matrix in Java Java program to find the transpose of a matrix (of any order), we interchange its rows and columns to obtain the transpose. Matrix transpose in Java import java.util.Scanner; class TransposeAMatrix { public static void main(String args[]) { int m, n, c, d; Scanner in = new Scanner(System.in); System.out.println(“Enter…
Read more

Matrix multiplication in Java

  Matrix multiplication in Java Java program to multiply two matrices, before multiplication, we check whether they can be multiplied or not. We use the simplest method of multiplication. There are more efficient algorithms available. Also, this approach isn’t efficient for sparse matrices, which contains a large number of elements as zero. Java matrix multiplication…
Read more

Bubble sort in Java

  Bubble sort in Java Bubble sort in Java to sort numbers of an array in ascending/descending order. Bubble sort program in Java import java.util.Scanner; class BubbleSort { public static void main(String []args) { int n, c, d, swap; Scanner in = new Scanner(System.in); System.out.println(“Input number of integers to sort”); n = in.nextInt(); int array[]…
Read more

Java program to open Notepad

  Java program to open Notepad Java program to open Notepad, it’s a text editor installed in the Windows operating system and used for creating and editing text files. You may be writing Java programs in it, but you can also open it from your Java program. How to open Notepad using Java program? import…
Read more

Java programs

  Java programs Java programming: Java program consists of instructions that will be executed on a machine to perform a task. For example, say arrange given integers in ascending order. This page contains sample programs for beginners to understand how to use Java programming to write simple Java programs. These programs show how to get…
Read more