karthikeya Boyini

karthikeya Boyini

1,421 Articles Published

Articles by karthikeya Boyini

Page 113 of 143

Rule Of Three in C++

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

The Rule of three is a rule of thumb when using C++. This is kind of a good practice rule that says that If your class needs any ofa copy constructor, an assignment operator, or a destructor, defined explicitly, then it is likely to need all three of them.Why is this? It’s because, if your class requires any of the above, it is managing dynamically allocated resources and would likely be needing the other to successfully achieve that. For example, if you require an assignment operator, you would be creating copies of objects currently being copied by reference, hence allocating ...

Read More

What is the size of int, long type as per C++ standard?

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

Here we will see what are the sizes of the int and long type data in C++. The sizes are depending on the system architecture and the Operating system.So in the 32-bit system, the standard is ILP32. In this standard the int, long and the pointer variables are of 32-bits.For the 64-bit system there are two variations. For Linux Operating system the standard is LP64. Here long and pointer are of 64-bits, but int are of 32-bits. For the Windows operating system, the standard is LLP64. Here long long is 64-bit, but int and long are of 32-bits.Example#include using ...

Read More

How to automatically generate a stacktrace when a gcc C++ program crashes?

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

For Linux and we can use gcc to compile C/C++ codes. This compiler uses glibc library. We can use the backtrace() function to trace the error. This function is present inside the execinfo.h header file. In this example, we are going to display Segmentation fault error using the stack trace feature.Example#include #include #include #include #include using namespace std; void error_handler(int sig) {    void *array[10];    size_t size;    size = backtrace(array, 10); //get the void pointers for all of the entries    cout

Read More

Java Program to display the contents in JTextArea

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

The following is an example to display the contents of a text file in JTextArea −Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class SwingDemo {    private JFrame mainFrame;    private JLabel statusLabel;    private JPanel controlPanel;    public SwingDemo() {       prepareGUI();    }    public static void main(String[] args) {       SwingDemo demo = new SwingDemo();       demo.showTextAreaDemo();    }    private void prepareGUI() {       mainFrame = new JFrame("Java Swing");       mainFrame.setSize(400, 400);       mainFrame.setLayout(new GridLayout(3, 1));       mainFrame.addWindowListener(new WindowAdapter() {     ...

Read More

What is the difference between static_cast<> and C style casting?

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

Here we will see what are the differences between static_cast and normal C style cast.The normal cast like (int)x is C style typecasting where static_cast(x) is used in C++.This static_cast() gives compile time checking facility, but the C style casting does not support that. This static_cast() can be spotted anywhere inside a C++ code. And using this C++ cast the intensions are conveyed much better.In C like cast sometimes we can cast some type pointer to point some other type data.Like one integer pointer can also point character type data, as they are quite similar, only difference is character has ...

Read More

How to activate and deactivate JFrame in Java

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

Here, we are activating a frame. For deactivation, we have used dispose −Thread.sleep(2000); frame.setVisible(false);The frame first activates and then deactivates after 2 seconds since we have set sleep to 2000 miliseconds.The following is an example to activate and deactivate JFrame −Exampleimport java.awt.Frame; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(String[] args) throws InterruptedException {       JFrame frame = new JFrame();       frame.add(new JLabel("Demo"));       frame.pack();       frame.setVisible(true);       Thread.sleep(2000);       frame.setState(Frame.ICONIFIED);       Thread.sleep(2000);       frame.setVisible(false);       frame.dispose(); ...

Read More

How to print Unicode character in C++?

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

To print the Unicode characters, the process is very similar to the actual printing process in C++.We can put the Unicode value with the prefix \u. Thus we can successfully print the Unicode character.Note: If the console does not support Unicode, then you cannot get the correct result. Here we have used the Linux system to solve this problem.Example#include using namespace std; int main() {    cout

Read More

Java Program to create JRadioButton from text

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

The following is an example to create JRadioButton from text −Examplepackage 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("Cricket");       JRadioButton radio2 = new JRadioButton("Football");       ButtonGroup group = new ButtonGroup();       group.add(radio1);       group.add(radio2);       radio1.setSelected(true);       JFrame frame = new JFrame();       frame.setLayout(new FlowLayout());       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.add(new JLabel("Fav Sports:"));       frame.add(radio1);     ...

Read More

How can we clear all selections in Java Swing JList?

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

To clear all selections, use the List clearSelection() method in Java −JList list = new JList(sports); list.clearSelection();Above, the elements in Sports array is a String array −String sports[]= { "Cricket", "Football", "Hockey", "Rugby"};The following is an example to clear all selection in JList −Examplepackage my; import java.awt.event.*; import java.awt.*; import javax.swing.*; class SwingDemo extends JFrame {    static JFrame frame;    static JList list;    public static void main(String[] args) {       frame = new JFrame("JList Demo");       SwingDemo s = new SwingDemo();       JPanel panel = new JPanel();       String sports[]= ...

Read More

How to set minimum size limit for a JFrame in Java

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

Use the setMinimumSize() method to set the minimum size limit for a JFrame −JFrame frame = new JFrame(); frame.setMinimumSize(new Dimension(500, 300));The following is an example to set minimum size limit for a JFrame −Exampleimport java.awt.Color; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JButton button = new JButton("Close!");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setContentPane(button);       button.addActionListener(e -> {          frame.dispose();       });       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.setMinimumSize(new Dimension(500, ...

Read More
Showing 1121–1130 of 1,421 articles
« Prev 1 111 112 113 114 115 143 Next »
Advertisements