Samual Sam has Published 2492 Articles

Which datatype is should I use to set a column for 5-star rating?

Samual Sam

Samual Sam

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

530 Views

You can use ENUM datatype for this. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    UserRating ENUM('1', '2', '3', '4', '5') ); Query OK, 0 rows affected (0.54 sec)Insert records in the table using insert command −mysql> insert into ... Read More

Extracting only date from datetime field in MySQL and assigning it to PHP variable?

Samual Sam

Samual Sam

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

581 Views

You need to use DateTime class if you want to extract the only date from datetime field. The syntax is as follows −DateTime::createFromFormat("Y-m-d H:i:s", yourDateTimeValue)->format("yourFormatSpecifier");Now you can implement the above syntax in your PHP code to extract the only date from datetime field. The PHP code is as follows −$MySQLDataBaseDateTime ... Read More

Java Program to replace key and value in HashMap with identical key and different values

Samual Sam

Samual Sam

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

241 Views

Create a HashMap and set key-value pair −Mapmap = new HashMap(); map.put(10, "A"); map.put(20, "B"); map.put(30, "C"); map.put(40, "D"); map.put(50, "E"); map.put(60, "F"); map.put(70, "G"); map.put(80, "H");Now, let’s say you need to set a different value for an identical key. For that, use put() −map.put(30, "T");Example Live Demoimport java.util.HashMap; import java.util.Map; ... Read More

Heap overflow and Stack overflow

Samual Sam

Samual Sam

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

467 Views

Heap OverflowHeap is used to store dynamic variables. It is a region of process’s memory. malloc(), calloc(), resize() all these inbuilt functions are generally used to store dynamic variables.Heap overflow occurs when −A) If we allocate dynamic large number of variables −int main() {    float *ptr = (int *)malloc(sizeof(float)*1000000.0)); ... Read More

How to select from a set of integers in MySQL?

Samual Sam

Samual Sam

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

179 Views

To select from a set of integers, you can use UNION. Following is the syntax −SELECT yourValue1 UNION SELECT yourValue2 UNION SELECT yourValue3 UNION SELECT yourValue4 . . . . NLet us implement the above syntax to select from a set of integers in MySQL −mysql> SELECT 1000 UNION SELECT 2000 ... Read More

How to track the order of insertion using Java collections?

Samual Sam

Samual Sam

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

176 Views

To track the order of insertion, you can use Map.Entry() in case of a Map. Let’s say we have the following LinkedHashMap −Mapmap = new LinkedHashMap(); map.put("Jack", 0); map.put("Tim", 1); map.put("David", 2); map.put("Tom", 3); map.put("Kevin", 4); map.put("Jeff", 5);Now, loop through Map.Entry and get the order of insertion correctly with Key ... Read More

MySQL order by from highest to lowest value?

Samual Sam

Samual Sam

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

2K+ Views

To order by from highest to lowest value, you can use ORDER BY DESC command −select *from yourTableName order by yourColumnName DESC;If you want the result from lowest to highest, you can use ORDER BY ASC command −select *from yourTableName order by yourColumnName ASC;Let us first create a table −mysql> ... Read More

How to use poll() in android ConcurrentLinkedDeque?

Samual Sam

Samual Sam

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

95 Views

Before getting into an example, we should know what ConcurrentLinkedDeque is, it is unbounded deque based on linked nodes. Multiple threads can access deque elements with safety.This example demonstrates about How to use poll() in android ConcurrentLinkedDequeStep 1 − Create a new project in Android Studio, go to File ⇒ ... Read More

C++ Program to Implement Hash Tables with Quadratic Probing

Samual Sam

Samual Sam

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

2K+ Views

A hash table is a data structure which is used to store key-value pairs. Hash function is used by hash table to compute an index into an array in which an element will be inserted or searched. Quadratic probing is a collision resolving technique in Open Addressed Hash tables. It ... Read More

How to use null value as key in Java HashMap

Samual Sam

Samual Sam

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

2K+ Views

Yes, you can set null as key in Java HashMap. For this, let’s first create a HashMap with key and value pair −Mapmap = new HashMap(); map.put("Football", "A"); map.put("Squash", "B"); map.put("Cricket", "C"); map.put("Hockey", "D"); map.put("Rugby", "E");Now, let’s add null value as key −map.put(null, "H");You can try to get the value ... Read More

Advertisements