Karthikeya Boyini has Published 2193 Articles

Bool to int conversion in C++

karthikeya Boyini

karthikeya Boyini

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

13K+ Views

Here we will see how to convert bool to int equivalent in C++. Bool is a datatype in C++, and we can use true or false keyword for it. If we want to convert bool to int, we can use typecasting. Always true value will be 1, and false value ... Read More

How to change JLabel font in Java

karthikeya Boyini

karthikeya Boyini

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

14K+ Views

To change JLabel font, use the setFont() method −JLabel lable = label.setFont(new Font("Verdana", Font.PLAIN, 18));Examplepackage my; import java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Label Example");       JLabel label;       label = ... Read More

Difference between “int main()” and “int main(void)” in C/C++?

karthikeya Boyini

karthikeya Boyini

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

3K+ Views

Sometimes we see that there are two types of main function definition. The int main() and int main(void). So is there any difference?In C++, there is no difference. In C also both are correct. But the second one is technically better. It specifies that the function is not taking any ... Read More

How to change text font for JLabel with HTML in Java?

karthikeya Boyini

karthikeya Boyini

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

996 Views

To change text font, you can use the setFont() method of JLabel −label.setFont(new Font("Verdana", Font.PLAIN, 12));The following is an example to change text font for JLabel with HTML −Exampleimport java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new ... Read More

Java Program to set alignment for text in JLabel

karthikeya Boyini

karthikeya Boyini

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

8K+ Views

JLabel Left AlignedThe following is an example to set left alignment for JLabel −Exampleimport java.awt.Font; import javax.swing.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Label Demo");       JLabel label;       label = new JLabel("Left aligned!", ... Read More

Difference between #define and const in C

karthikeya Boyini

karthikeya Boyini

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

882 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

1K+ 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

3K+ 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

8K+ 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

203 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

Advertisements