Namespace in C++

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

247 Views

Consider a situation, when we have two persons with the same name, Zara, in the same class. Whenever we need to differentiate them definitely we would have to use some additional information along with their name, like either the area, if they live in different area or their mother’s or father’s name, etc.Same situation can arise in your C++ applications. For example, you might be writing some code that has a function called xyz() and there is another library available which is also having same function xyz(). Now the compiler has no way of knowing which version of xyz() function ... Read More

Rename ID Field After MongoDB Group Aggregation

George John
Updated on 30-Jul-2019 22:30:25

2K+ Views

Yes, it is possible to rename using aggregation. Let us first create a collection with documents> db.renameIdDemo.insertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a1760353decbc2fc927c5") } > db.renameIdDemo.insertOne({"StudentName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a1765353decbc2fc927c6") } > db.renameIdDemo.insertOne({"StudentName":"David"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a176b353decbc2fc927c7") }Following is the query to display all documents from a collection with the help of find() method> db.renameIdDemo.find();This will produce the following output{ "_id" : ObjectId("5c9a1760353decbc2fc927c5"), "StudentName" : "Chris" } { "_id" : ObjectId("5c9a1765353decbc2fc927c6"), "StudentName" : "Robert" } { "_id" : ObjectId("5c9a176b353decbc2fc927c7"), "StudentName" : "David" }Following is the query to ... Read More

Copy Data from One Field to Another in MySQL

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

2K+ Views

To copy data from one field to another on every row, use the UPDATE command.Let us first create a table −mysql> create table DemoTable    (    StudentId int,    StudentFirstName varchar(20),    StudentMarks int default 0    ); Query OK, 0 rows affected (0.49 sec)Following is the query to insert records in the table using insert command −mysql> insert into DemoTable(StudentId, StudentFirstName) values(89, 'Larry'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentId, StudentFirstName) values(35, 'Robert'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(StudentId, StudentFirstName) values(48, 'Chris'); Query OK, 1 row affected (0.13 sec) ... Read More

Find Connected Components of an Undirected Graph in C++

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

935 Views

Weakly or Strongly Connected for a given a undirected graph can be found out using DFS. This is a C++ program of this problem.Functions usedBegin Function fillorder() = fill stack with all the vertices.    a) Mark the current node as visited and print it    b) Recur for all the vertices adjacent to this vertex    c) All vertices reachable from v are processed by now, push v to Stack End Begin Function DFS() :    a) Mark the current node as visited and print it    b) Recur for all the vertices adjacent to this vertex EndExample#include ... Read More

Setting Column Values as Column Names in MySQL Query Result

Samual Sam
Updated on 30-Jul-2019 22:30:25

4K+ Views

To set column values as column names in the query result, you need to use a CASE statement.The syntax is as follows −select yourIdColumnName, max(case when (yourColumnName1='yourValue1') then yourColumnName2 else NULL end) as 'yourValue1', max(case when (yourColumnName1='yourValue2') then yourColumnName2 else NULL end) as 'yourValue2', max(case when yourColumnName1='yourValue3') then yourColumnName2 else NULL end) as 'yourValue3’, . . N from valueAsColumn group by yourIdColumnName order by yourIdColumnName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table valueAsColumn    -> (    -> UserId int,    -> UserColumn1 varchar(10),    -> ... Read More

Duration withNanos Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

136 Views

The immutable copy of a duration with the required nanoseconds is obtained using the method withNanos() in the Duration class in Java. This method requires a single parameter i.e. the number of nanoseconds and it returns the duration with the required nanoseconds that were passed as a parameter.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { int nanoseconds = 1000000; Duration duration = Duration.ofHours(10); System.out.println("The duration ... Read More

Quartet Class in JavaTuples

Samual Sam
Updated on 30-Jul-2019 22:30:25

142 Views

A Quartet class is a Tuple of four elements. It is part of the JavaTuples library.The following is the declaration −public final class Quartet extends Tuple implements IValue0, IValue0, IValue0, IValue0Let us first see what we need to work with JavaTuples. To work with Quartet class in JavaTuples, you need to import the following package −import org.javatuples.Quartet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Quartet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is ... Read More

Bind Variables in JDBC: How to Execute a Query

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

7K+ Views

A bind variable is an SQL statement with a temporary variable as place holders which are later replaced with appropriate values. For example, if you have a table named employee in the database created as shown below:+---------+--------+----------------+ | Name | Salary | Location | +---------+--------+----------------+ | Amit | 30000 | Hyderabad | | Kalyan | 40000 | Vishakhapatnam | | Renuka | 50000 | Delhi | | Archana | ... Read More

Instant toString Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

305 Views

The range of values for a field can be obtained using the range() method in the Instant class in Java. This method requires a single parameter i.e. the ChronoField for which the range of values are required and it returns the range of valid values for the ChronoField.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoField; import java.time.temporal.ValueRange; public class Demo { public static void main(String[] args) { Instant i = Instant.now(); ValueRange range1 = i.range(ChronoField.MILLI_OF_SECOND); ... Read More

Instant equals Method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

1K+ Views

The equality of two Instant objects can be determined using the equals() method in the Instant class in Java. This method requires a single parameter i.e. the Instant to be compared. Also it returns true if both the Instant objects are equal and false otherwise.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo {    public static void main(String[] args) {       Instant i1 = Instant.parse("2019-01-13T16:10:35.00Z");       Instant i2 = Instant.parse("2019-01-13T16:10:35.00Z");       System.out.println("Instant object i1 is: " + i1);       System.out.println("Instant object i2 is: " ... Read More

Advertisements