karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 115 of 143

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

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 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 argument. In C if some function is not specified with the arguments, then it can be called using no argument, or any number of arguments. Please check these two codes. (Remember these are in C not C++)Example#include void my_function() {    //some task } main(void) {    my_function(10, "Hello", "World"); ...

Read More

How to add tooltip to JLabel in Java?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 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 static void main(String args[]) {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("Demo Label!");       label.setFont(new Font("Verdana", Font.PLAIN, 14));       label.setToolTipText("This is a demo tooltip");       Border border = BorderFactory.createLineBorder(Color.ORANGE);     ...

Read More

How to Map IntSteam to String object in Java

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 229 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[] args) throws Exception {       IntStream.range(1, 10)       .mapToObj(val -> "z" + val)       .forEach(System.out::println);    } }Outputz1 z2 z3 z4 z5 z6 z7 z8 z9

Read More

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

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 459 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,    -> Number2 int,    -> AddResult int,    -> MinusResult int,    -> MultiplyResult int,    -> DivideResult int    -> ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Number1, Number2) values(40, 20); Query OK, 1 row affected (0.16 ...

Read More

How to change JLabel size in Java?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 9K+ 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[]) {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("This is demo label!", JLabel.RIGHT);       label.setVerticalAlignment(JLabel.TOP);       label.setFont(new Font("Verdana", Font.PLAIN, 15));       label.setPreferredSize(new Dimension(250, 100));       label.setForeground(new Color(120, 90, 40));       label.setBackground(new ...

Read More

Set Bounds for JProgressBar in Java Swing

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 423 Views

Use the setBounds() method to set Bounds for JProgressBar in Java Swing −JProgressBar progressBar; progressBar.setBounds(70, 50, 120, 30);The following is an example to set bounds for JProgressBar −Examplepackage my; import javax.swing.*; public class SwingDemo extends JFrame {    JProgressBar progressBar;    int i = 0;    SwingDemo() {       progressBar = new JProgressBar(0, 1000);       progressBar.setBounds(70, 50, 120, 30);       progressBar.setValue(0);       progressBar.setStringPainted(true);       add(progressBar);       setSize(550, 150);       setLayout(null);    }    public void inc() {       while (i

Read More

How will implement Your Own sizeof in C

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 3K+ Views

To use the sizeof(), we can take the value using a variable x, using &x, it will print the address of it. Now if we increase the value of &x then it may increase in different way. If only one byte is increased, that means it is character, if the increased value is 4, then it is int or float and so on. So by taking the difference between &x + 1 and &x, we can get the size of x.Here we will use macro as the datatype is not defined in the function. And one more thing, we are ...

Read More

How can we set Mnemonic Key Radio Button in Java?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 537 Views

Mnemonic key is set so that a user can use Keyboard keys to select a Radio Button. For example, a key can be set with ALT −radio2.setMnemonic(KeyEvent.VK_R);Above, we have set key ALT+R for radio2.The following is an example to set Mnemonic key radio button −package my; import java.awt.FlowLayout; import java.awt.event.KeyEvent; import javax.swing.ButtonGroup; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JRadioButton; public class SwingDemo {    public static void main(String[] args) {       JRadioButton radio1 = new JRadioButton("Male");       JRadioButton radio2 = new JRadioButton("Female");       radio2.setMnemonic(KeyEvent.VK_R);       ButtonGroup group = new ButtonGroup();       ...

Read More

How to correctly use INSERT INTO … SELECT in MySQL to avoid Error 1064?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 718 Views

Let us first create a table −mysql> create table DemoTable1    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> FirstName varchar(100)    -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(FirstName) values('John'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1(FirstName) values('Chris'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;This will produce the following output −+----+-----------+ | Id | FirstName | +----+-----------+ | 1 | John ...

Read More

How can we grant a user to access all stored procedures in MySQL?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 1K+ Views

Let us first display all users and host from the table MySQL.user −mysql> select user, host from Mysql.user;This will produce the following output −+------------------+-----------+ | user             | host      | +------------------+-----------+ | Bob              | %         | | Charlie          | %         | | Robert           | %         | | User2 | % ...

Read More
Showing 1141–1150 of 1,421 articles
« Prev 1 113 114 115 116 117 143 Next »
Advertisements