Found 9150 Articles for Object Oriented Programming

Java Virtual Machine (JVM) Stack Area

AmitDiwan
Updated on 07-Jul-2020 08:15:24

985 Views

Following are some key points to undertstand JVM Stack Area −During the creation of a thread, the Java Virtual Machine creates a separate stack.The JVM performs only two operations upon this stack. The operations are push (i.e insert) and pop (i.e delete).When a thread is currently in execution, the stack associated with it is known as runtime stack.Every method call done by the thread, intermediate calculations, assignment of local variables, calling parameters etc, are stored as an operation in the runtime stack.Once the thread stops or completes executing, the respective part from the stack is deleted.Once all the calls by ... Read More

Java program for iterative quick sort

AmitDiwan
Updated on 18-Nov-2024 22:32:01

859 Views

In this program, we will perform an iterative quick sort in Java to sort an array of integers. Instead of using recursion, the program uses an iterative approach with an auxiliary stack to manage the sorting process. The output will display the sorted array after applying the quick sort algorithm. Problem Statement Write a Java program to sort an array of integers using the iterative quick sort method. Below is the demonstration of the same − Input {34, 76, 41, 32, 11, 0, 91, 102, -11} Output After iteratively performing quick sort, the array is -11 0 11 32 34 ... Read More

Java Program for Gnome Sort

AmitDiwan
Updated on 04-Dec-2024 22:05:31

402 Views

Gnome Sort, also known as Stupid Sort, is a simple sorting algorithm that works by iterating through a list, comparing adjacent elements, and swapping them if they are in the wrong order. If a swap occurs, the algorithm moves one step backward to recheck the order, otherwise, it moves forward. This process continues until the array is sorted. In this article, we will explain the working of Gnome Sort using Java. Gnome Sort Approach Start from the first element. Compare the current element with the previous one: ... Read More

Java Program for Reversal algorithm for array rotation

AmitDiwan
Updated on 07-Jul-2020 08:04:24

336 Views

Following is the Java program to implement Reversal algorithm for array rotation −Example Live Demoimport java.io.*; public class Demo{    static void rotate_left(int my_arr[], int no_of_rotation){       int n = my_arr.length;       array_reversal(my_arr, 0, no_of_rotation - 1);       array_reversal(my_arr, no_of_rotation, n - 1);       array_reversal(my_arr, 0, n - 1);    }    static void array_reversal(int my_arr[], int start, int end){       int temp;       while (start < end) {          temp = my_arr[start];          my_arr[start] = my_arr[end];          my_arr[end] = ... Read More

Java Program for Recursive Insertion Sort

AmitDiwan
Updated on 07-Jul-2020 07:57:49

948 Views

Following is the Java Program for Recursive Insertion Sort −Example Live Demoimport java.util.Arrays; public class Demo{    static void recursive_ins_sort(int my_arr[], int arr_len){       if (arr_len = 0 && my_arr[j] > last){          my_arr[j+1] = my_arr[j];          j--;       }       my_arr[j+1] = last;    }    public static void main(String[] args){       int my_arr[] = {11, 23, 67, 83, 42, 11, 0};       recursive_ins_sort(my_arr, my_arr.length);       System.out.println("The array elements after implementing insertion sort is ");       System.out.println(Arrays.toString(my_arr));    } }OutputThe ... Read More

Java program for recursive Bubble Sort

AmitDiwan
Updated on 27-Aug-2024 18:48:46

2K+ Views

In this article, we will learn to implement Bubble Sort using recursion in Java. Our goal is to understand how recursion can be applied to the Bubble Sort algorithm to achieve the same sorting effect as its iterative counterpart. Problem Statement Write a Java program to sort an array of integers using the recursive approach of Bubble Sort. Input my_arr[] = {45, 67, 89, 31, 63, 0, 21, 12} Output The array after implementing bubble sort is[0, 12, 21, 31, 45, 63, 67, 89] Bubble Sort Algorithm Bubble sort algorithm is a simple sorting algorithm to sort elements. ... Read More

Java program to calculate area of a tetrahedron

Alshifa Hasnain
Updated on 26-Feb-2025 19:36:26

472 Views

In this article, we will learn to calculate the area of a Tetrahedron using Java. A tetrahedron is a type of polyhedron that consists of four triangular faces. What is a tetrahedron? A tetrahedron is a three-dimensional polyhedron with four triangular faces, six edges, and four vertices. If all its faces are equilateral triangles, it is called a regular tetrahedron. The surface area of a regular tetrahedron can be calculated using the formula − 𝐴 = sqrt{3} . s^2 Where A is the surface area, where s is the length of a side of the tetrahedron. Calculating the Area of ... Read More

Java Program for array rotation

AmitDiwan
Updated on 10-Aug-2023 12:12:06

590 Views

An array is a linear data structure that is used to store a group of elements with similar datatypes. It stores data in a sequential manner. Once we create an array we can't change its size i.e. it can store a fixed number of elements. The array comes with a vast application and use case. Also, we can perform numerous operations on arrays. This article will help you to understand the basics of arrays and also, we will make java programs to perform right and left rotation operations on arrays. Java Program for Array Rotation First, let's understand the term ... Read More

Java program to print number series without using any loop

AmitDiwan
Updated on 22-Aug-2024 11:58:39

1K+ Views

In this article, we will learn how to print a sequence of numbers in Java, ranging from 0 to 15. To do this, we'll use recursion rather than using loops like for loop or while loop. Recursion is a programming technique where a method calls itself to perform a sub-operation as necessary. Problem Statement Write a Java program to print Number series without using any loop Output The numbers without using a loop have been printed below0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, Java program to print number series without using ... Read More

Java Program for Largest K digit number divisible by X

AmitDiwan
Updated on 07-Jul-2020 07:42:12

199 Views

Following is the Java program for largest K digit number divisible by X −Example Live Demoimport java.io.*; import java.lang.*; public class Demo{    public static int largest_k(int val_1, int val_2){       int i = 10;       int MAX = (int)Math.pow(i, val_2) - 1;       return (MAX - (MAX % val_1));    }    public static void main(String[] args){       int val_1 = 25;       int val_2 = 2;       System.out.println("The largest 2 digit number divisible by 25 is ");       System.out.println((int)largest_k(val_1, val_2));    } }OutputThe largest 2 ... Read More

Advertisements