How to implement a copy constructors in C++?

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

385 Views

Here we will see how the copy constructors are implemented in C++. Before discussing that we should know what is the copy constructor.The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to −Initialize one object from another of the same type.Copy an object to pass it as an argument to a function.Copy an object to return it from a function.If a copy constructor is not defined in a class, the compiler itself defines one. If the class has pointer ... Read More

How to change Button Border in Java Swing

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

744 Views

For Button border, use createLineBorder() method in Java, which allows you to set the color of the Border as well:JButton button = new JButton("Demo Button!"); Border border = BorderFactory.createLineBorder(Color.BLUE);The following is an example to change button border in Java:Exampleimport java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.border.Border; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Button Border");       Container container = frame.getContentPane();       JButton button = new JButton("Demo Button!");       Border border = BorderFactory.createLineBorder(Color.BLUE);       button.setBorder(border);   ... Read More

Java DatabaseMetaData supportsStoredProcedures() method with example

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

30 Views

The supportsStoredProcedures() method of the DatabaseMetaData interface is used to determine whether the underlying database supports stored procedures.This method returns a boolean value which is −True, when the underlying database supports stored procedures.False, when the underlying database doesn't support stored procedures.To determine whether the underlying database supports stored procedures−Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of a ... Read More

What is the syntax for boolean values in MongoDB?

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

5K+ Views

You can use $eq as well as $ne operator for boolean values. Let us first create a collection with documents −> db.booleanQueryDemo.insertOne({"UserName":"John", "UserAge":23, "isMarried":true}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc815c08f9e6ff3eb0ce44a") } > db.booleanQueryDemo.insertOne({"UserName":"Chris", "UserAge":21, "isMarried":false}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc815d08f9e6ff3eb0ce44b") } > db.booleanQueryDemo.insertOne({"UserName":"Robert", "UserAge":24, "isMarried":false}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc815dc8f9e6ff3eb0ce44c") } > db.booleanQueryDemo.insertOne({"UserName":"David", "UserAge":26, "isMarried":true}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc815ed8f9e6ff3eb0ce44d") }Following is the query to display all documents from a collection with the help of find() method −> db.booleanQueryDemo.find().pretty();This will produce the following output −{ ... Read More

Templates in C++ vs Generics in Java

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

2K+ Views

Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type.A template is a blueprint or formula for creating a generic class or a function. The library containers like iterators and algorithms are examples of generic programming and have been developed using template concept.There is a single definition of each container, such as vector, but we can define many different kinds of vectors for example, vector or vector .Example Code#include #include using namespace std; template inline T const& Max (T const& a, T const& b) { ... Read More

How to create Vertical progress bar occupying the entire frame in Java

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

146 Views

For this, create a vertical progress bar −JProgressBar progressBar = new JProgressBar(JProgressBar.VERTICAL); progressBar.setEnabled(true);Also, set the bounds −progressBar.setBounds(70, 50, 120, 30);The following is an example to create vertical progress bar occupying the entire frame −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JProgressBar; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       JProgressBar progressBar = new JProgressBar(JProgressBar.VERTICAL);       progressBar.setEnabled(true);       progressBar.setBounds(70, 50, 120, 30);       progressBar.setBackground(Color.orange);       progressBar.setForeground(Color.white);       progressBar.setStringPainted(true);       ... Read More

Merge two array fields in MongoDB?

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

544 Views

To merge, use $setUnion operator. Let us first create a collection with documents −> db.mergeTwoArrayFieldDemo.insertOne({"NaturalNumbers":[1,2,3,8,10,20,30],"WholeNumbers":[0,1,2,63,78,20,45]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd68e4057806ebf1256f11d") }Following is the query to display all documents from a collection with the help of find() method −> db.mergeTwoArrayFieldDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd68e4057806ebf1256f11d"),    "NaturalNumbers" : [       1,       2,       3,       8,       10,       20,       30    ],    "WholeNumbers" : [       0,       1,       2,       63,       78,       20,       45    ] }Following is the query to merge two array field in MongoDB.> db.mergeTwoArrayFieldDemo.aggregate([    { "$project": {       "MergedArray": { "$setUnion": [ "$NaturalNumbers", "$WholeNumbers" ] }    }} ]);This will produce the following output −{ "_id" : ObjectId("5cd68e4057806ebf1256f11d"), "MergedArray" : [ 0, 1, 2, 3, 8, 10, 20, 30, 45, 63, 78 ] }

How to use use an array of pointers (Jagged) in C/C++?

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

504 Views

Let us consider the following example, which uses an array of 3 integers −In CExample Live Demo#include const int MAX = 3; int main () {    int var[] = {10, 100, 200};    int i;    for (i = 0; i < MAX; i++) {       printf("Value of var[%d] = %d", i, var[i] );    }    return 0; }OutputValue of var[0] = 10 Value of var[1] = 100 Value of var[2] = 200In C++Example Live Demo#include using namespace std; const int MAX = 3; int main () {    int var[] = {10, 100, 200};    int i;    for (i = 0; i < MAX; i++) {       cout

What are the different types of nested classes are defined in Java?

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

773 Views

In Java, it is possible to define a class inside another class, such classes are called Nested classes. We can use the access modifiers like private, public, protected or default for inner classes and default or public access modifiers for outer class.There are two types of nested classes are defined in Java.Static Nested ClassNon-Static Nested ClassStatic Nested ClassWe Can define an inner class as static, so such type of classes is called a static nested class.The nested class is defined with the static keyword, so this type of nested classes doesn’t share any relationship with the instance of an outer class.A static ... Read More

What happens when you add a double value to a String in java?

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

2K+ Views

The “+” operator with a String acts as a concatenation operator.Whenever you add a String value to a double using the “+” operator, both values are concatenated resulting a String object.In-fact adding a double value to String is the easiest way to convert a double value to Strings.Exampleimport java.util.Scanner;    public class StringsExample {       public static void main(String args[]){          Scanner sc = new Scanner(System.in);          System.out.println("Enter a double value: ");          double d = sc.nextDouble();          System.out.println("Enter a String value: ");       ... Read More

Advertisements