Karthikeya Boyini has Published 2383 Articles

Catching base and derived classes exceptions in C++

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

1K+ Views

To catch an exception for both base and derive class then we need to put catch block of derived class before the base class. Otherwise, the catch block of derived class will never be reached.AlgorithmBegin    Declare a class B.    Declare another class D which inherits class B.   ... Read More

How to calculate the possibilities of duplication for random number within a range in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

138 Views

To get the duplicate numbers for random numbers in a range, loop through and create two Random class objects −Use nextInt() to get the next number −intrandVal1 = new Random().nextInt(50); intrandVal2 = new Random().nextInt(50);Now, compare both the above numbers −if (randVal1 == randVal2) {    System.out.println("Duplicate number = "+randVal1); }All ... Read More

Is there any easy way to add multiple records in a single MySQL query?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

131 Views

You can easily add multiple items with only one insert command. The syntax is as follows −insert into yourTableName(yourColumnName1, yourColumnName2, ......N) values(yourValue1, yourValue2, ....N), (yourValue1, yourValue2, ....N), ..........N;Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value1 int,    Value2 ... Read More

ByteBuffer asCharBuffer() method in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

86 Views

A view of the ByteBuffer can be created as a CharBuffer using the asCharBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a char buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is ... Read More

Set Date value in Java HashMap?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

1K+ Views

Create a Calendar instance and Date object −Calendar cal = Calendar.getInstance(); Date date = new Date(); cal.setTime(date);Now, create a HashMap and store Date value −LinkedHashMaphashMap = new LinkedHashMap(); hashMap.put("year", cal.get(Calendar.YEAR)); hashMap.put("month", cal.get(Calendar.MONTH)); hashMap.put("day", cal.get(Calendar.DAY_OF_MONTH));Example Live Demoimport java.util.Calendar; import java.util.Date; import java.util.LinkedHashMap; public class Demo {    public static void main(String[] argv) ... Read More

How do I change the case on every field in a MySQL table in a single call?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

79 Views

You can use update along with lower() function for this. Let us first create a table −mysql> create table DemoTable (    Id varchar(100),    StudentFirstName varchar(20),    StudentLastName varchar(20),    StudentCountryName varchar(10) ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> ... Read More

How to write a for loop in a JSP page?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

6K+ Views

Following is the for loop example − FOR LOOP Example JSP Tutorial The above code will generate the following result −JSP Tutorial JSP Tutorial JSP Tutorial

ByteBuffer allocate() method in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

349 Views

A new ByteBuffer can be allocated using the method allocate() in the class java.nio.ByteBuffer. This method requires a single parameter i.e. the capacity of the buffer. It returns the new ByteBuffer that is allocated. If the capacity provided is negative, then the IllegalArgumentException is thrown.A program that demonstrates this is ... Read More

Java Program to get frequency of words with Lambda Expression

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

403 Views

Let’s say the following is the List −List list = Arrays.asList("Welcome", "to", "the", "club", "club", "the");No, let us create a Map to get the frequency of words. Here, we are using Lambda Expression as well −Map map = list    .parallelStream()    .flatMap(a -> Arrays.asList(a.split(" ")).stream())    .collect(    Collectors.toConcurrentMap(c ... Read More

How to treat NULL as 0 and add columns in MySQL?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

484 Views

Use the concept of IFNULL() method to treat NULL as 0. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value1 int,    Value2 int ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using ... Read More

Advertisements