AmitDiwan has Published 10740 Articles

Max Heap in Java

AmitDiwan

AmitDiwan

Updated on 07-Jul-2020 08:17:19

3K+ Views

Max heap is a complete binary tree, wherein the value of a root node at every step is greater than or equal to value at the child node.Below is an implementation of Max Heap using library functions.Example Live Demoimport java.util.*; public class Demo{    public static void main(String args[]){     ... Read More

Java Virtual Machine (JVM) Stack Area

AmitDiwan

AmitDiwan

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

1K+ 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 ... Read More

Java Program for Reversal algorithm for array rotation

AmitDiwan

AmitDiwan

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

375 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);     ... Read More

Java Program for Recursive Insertion Sort

AmitDiwan

AmitDiwan

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

1K+ 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--;       }   ... Read More

Java Program for Largest K digit number divisible by X

AmitDiwan

AmitDiwan

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

222 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 ... Read More

How to detect if a MySQL database structure changed (not content)?

AmitDiwan

AmitDiwan

Updated on 06-Jul-2020 11:39:59

323 Views

Let us first see an example and create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(40),    StudentAge int,    StudentMarks int ); Query OK, 0 rows affected (0.76 sec)Following is the query to know the database structure −mysql> show ... Read More

Change only dates, ignoring time records in MySQL

AmitDiwan

AmitDiwan

Updated on 06-Jul-2020 09:17:34

145 Views

To change only dates, not time, use the MySQL INTERVAL and YEAR. Since, we will be updating the records, therefore, use UPDATE and set a new value with INTERVAL.Let us see an example and create a table −mysql> create table DemoTable (    DueDate datetime ); Query OK, 0 rows ... Read More

How to count rows from two tables in a single MySQL query?

AmitDiwan

AmitDiwan

Updated on 06-Jul-2020 08:56:03

446 Views

Let us first create a table −mysql> create table DemoTable1 (    Name varchar(40) ); Query OK, 0 rows affected (0.81 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values('Chris'); Query OK, 1 row affected (0.48 sec) mysql> insert into DemoTable1 values('Robert'); Query OK, 1 ... Read More

MySQL query to generate row index (rank) in SELECT statement?

AmitDiwan

AmitDiwan

Updated on 06-Jul-2020 07:40:48

1K+ Views

To generate a row index, use ROW_NUMBER(). Let us first create a table −mysql> create table DemoTable (    Name varchar(40) ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> ... Read More

Search text containing a new line in MySQL?

AmitDiwan

AmitDiwan

Updated on 06-Jul-2020 06:00:18

812 Views

You can use REGEXP. Let us first create a table −mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (1.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('JohnSmith'); Query OK, 1 row affected (0.73 sec) mysql> insert into DemoTable ... Read More

Advertisements