Karthikeya Boyini has Published 2383 Articles

Difference between #define and const in C

karthikeya Boyini

karthikeya Boyini

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

728 Views

The #define is preprocessor directives. So when we define some macro using #define, it replaces into the code with its value before compilation. So when the compiler does not know anything about the code, in that time also the macro values are replaced.The constant is actually a variable. By declaring ... Read More

How to add tooltip to JLabel in Java?

karthikeya Boyini

karthikeya Boyini

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

796 Views

Tooltip is visible whenever you will place the mouse cursor on the label. Use the setToolTipText() method to add tooltip to JLabel −label.setToolTipText("This is a demo tooltip");The following is an example to add tooltip to JLabel −Exampleimport java.awt.Color; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo {    public ... Read More

How to filter String stream and map to lower case in Java? Perform sort as well.

karthikeya Boyini

karthikeya Boyini

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

2K+ Views

Let’s say the following is String array, which we have converted to List −Arrays.asList("DE", "GH", "JK", "MN", "PQ", "RS", "TU", "VW", "XY", "BC")Now filter String stream and map to lower case −.stream() .filter(a-> a.startsWith("V")) .map(String::toLowerCase)To sort now, use the sorted() and display using forEach().The following is an example to filter ... Read More

Using range in switch case in C/C++

karthikeya Boyini

karthikeya Boyini

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

6K+ Views

In C or C++, we have used the switch-case statement. In the switch statement we pass some value, and using different cases, we can check the value. Here we will see that we can use ranges in the case statement.The syntax of using range in Case is like below −case ... Read More

How to Map IntSteam to String object in Java

karthikeya Boyini

karthikeya Boyini

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

156 Views

To Map IntStream to String object, use mapToObj and within that set the values −.mapToObj(val -> "z" + val)Before that, we used range() on IntStream −IntStream.range(1, 10)The following is an example to map IntStream to String object in Java −Exampleimport java.util.stream.IntStream; public class Demo {    public static void main(String[] ... Read More

Nested functions in C

karthikeya Boyini

karthikeya Boyini

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

4K+ Views

In some applications, we have seen that some functions are declared inside another function. This is sometimes known as nested function, but actually this is not the nested function. This is called the lexical scoping. Lexical scoping is not valid in C because the compiler is unable to reach correct ... Read More

Java Program to Map String list to lowercase and sort

karthikeya Boyini

karthikeya Boyini

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

409 Views

Let’s say the following is our String List −List list = new ArrayList(); list.add("ABC"); list.add("CDE"); list.add("GHI"); list.add("MNO"); list.add("GWE"); list.add("WDF"); list.add("JYH"); list.add("TYU");Map String List to lowercase −list .stream() .map(String::toLowerCase)After that, perform sorting −sorted((val1, val2) -> val2.compareTo(val1))The following is an example to Map string list to lowercase and sort −Exampleimport java.util.ArrayList; import ... Read More

MySQL query to get the current date from the list of dates

karthikeya Boyini

karthikeya Boyini

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

93 Views

For the current day, you can use CURDATE() method. Let us first create a table −mysql> create table DemoTable    -> (    -> DueDate date    -> ); Query OK, 0 rows affected (1.35 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-06-14' ); ... Read More

Execute operations (plus, minus, multiply, divide) while updating a MySQL table?

karthikeya Boyini

karthikeya Boyini

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

300 Views

Following is the syntax executing the plus (+) operator −update yourTableName set yourColumnName3=(yourColumnName1+yourColumnName2)The above syntax is only for plus operator. You need to change symbol like -, *, / for other operations. Let us first create a table −mysql> create table DemoTable    -> (    -> Number1 int,   ... Read More

How to change JLabel size in Java?

karthikeya Boyini

karthikeya Boyini

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

7K+ Views

With Java Swing, you can set JLabel size as preferred size different than the default −JLabel label.setPreferredSize(new Dimension(250, 100));The following is an example to change JLabel size −Exampleimport java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {     ... Read More

Advertisements