The mutable storage class in C++ is a property that gives you access to modify the non-static data members (not static data members) of a class, even when the object is declared as constant. This is mainly useful for scenarios where the data needs modification without affecting the logical state of the object, like caching, lazy initialization, and logging. Syntax class class_name { mutable data_type member_name; }; Here is the following syntax for the mutable storage class, which is declared using the mutable keyword and applied to only non-static data members of a class. Example #include ... Read More
Standard Library header files are the predefined files in C++, which are part of the built-in library. It consists of declarations for functions, classes, objects, and macros. These header files give you access to perform various operations like input/output, string manipulation, containers, algorithms, math operations, and many more. Here is the following list of all the types of libraries under the standard Library Header Files. Utilities library Dynamic memory management Numeric limits Error handling String library ... Read More
The C++ programming language is a set of instructions that tells the compiler how to perform specific tasks. These instructions consist of functions and statements, which, when compiled and executed, tell the computer what action to perform. Prerequisite To compile and execute the program following prerequisites need to be met. Compiler: Any compiler downloaded and installed, like GCC, Clang, or MSVC, or an IDE (like Visual Studio Code, Code::Blocks, or Eclipse). Source program: And a source program file saved as name.cpp (example: Myfile.cpp) Instructions Here are the following instructions to ... Read More
Operator overloading in C++ is the feature that allows you to define how operators will behave for user-defined data types like classes and structures. Operator overloading and function overloading both support compile-time polymorphism. In the following article, we will learn the rules that need to be followed for operator overloading. Rules for Operator Overloading Only built-in operators can be overloaded. If some operators are not present in C++, we cannot overload them. The arity of the operators cannot be changed. The precedence and associativity of the operators ... Read More
The given task is to overwrite a line in a .txt file with new content. Assume we have a .txt file with the following content - Line 1: Hello World Line 2: This is a test file. Line 3: This line will be overwritten. Line 4: Goodbye! We want to overwrite line 3 with "This line has been changed". Following will be the resultant content - line 1: Hello World line 2: This is a test file. line 3: This line has been changed. line 4: Goodbye! Overwriting a Line in a ".txt" File There are no direct methods ... Read More
In this article, we will learn to insert multiple tabs into a single JTabbedPane in Java. The Java Swing's JTabbedPane enables you to group content into several tabs in one container. JTabbedPane A JTabbedPane is a component can extends the JComponent class, and we can able to see only one tab at a time. Each tab is associated with a single component that can be displayed when the tab is selected. Syntax Object declaration and instantiation using the Java class JTabbedPane: JTabbedPane tabbedPane = new JTabbedPane(); A JTabbedPane can generate a ChangeListener interface when a tab is ... Read More
JTable component in Swing provides an effective method for showing and editing tabular information. JTable automatically supports re-ordering columns through dragging of column headers by default. In this article, we will learn to prevent the re-ordering of columns of a JTable in Java. JTable A JTable is a subclass of the JComponent class, and it can be used to create a table with information displayed in multiple rows and columns. Syntax The following is the syntax for JTable initialization: JTable table = new JTable(data, columnNames); When a value is selected from a JTable, a TableModelEvent is generated, which is handled ... Read More
JTextArea is one of the most common Swing-based components. By default, it does not support text formatting such as bold, italics, or colored text inside a textarea. In this article, we will learn to display bold text inside the JTextArea in Java. What is a JTextArea? A JTextArea class can extend JTextComponent and allow a user to enter multiple lines of text inside it. A JTextArea can generate a CaretListener interface, which can listen to caret update events. Syntax The following is the syntax for JTextArea initialization: JTextArea textArea = new JTextArea(); Adding Bold Text Inside the JTextArea We ... Read More
In this article, we will learn to implement an editable JLabel in Java. An editable JLabel is a label component that can be converted to an editable text field when clicked. JLabel A JLabel class can extend the JComponent class, and an object of JLabel provides text instructions or information on a GUI. A JLabel can display a single line of read-only text, an image, or both text and image. Syntax The following is the syntax for JLabel initialization: JLabel label = new JLabel("Tutorials Point"); A JLabel can explicitly generate a PropertyChangeListener interface. Methods The important methods of a ... Read More
Quick sort algorithm is also known as partition exchange sort and is based on partitioning of an array of data into smaller sub-arrays. A large array is partitioned into two arrays such that the left sub-array holds values smaller than the pivot element and the right sub-array holds values greater than the pivot value. Quicksort partitions an array and then calls itself recursively twice to sort the two resulting sub-arrays: left and right sub-arrays. Quick sort falls uses the divide and conquer approach of problem-solving methodology. This algorithm is ... Read More