Performance Difference Between i++ and ++i in C++ Program

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

2K+ Views

The effective result of i++ and ++i are same. The only difference is that the i++ increases the value of i after assigning it, and for ++i, it increases the value first, then assigns its value. We can see the difference in the following code.Example Code#include using namespace std; int main() {    int x = 3, y, z;    y = x++;    z = ++x;    cout

Use Current Date for Timestamp Default in MySQL

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

131 Views

Use the CURRENT_TIMESTAMP instead of current_date() in MySQL for timestamp default current_date. Let us first create a table. Following is the query −mysql> create table defaultCurrent_DateDemo    -> (    -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> StudentName varchar(20),    -> StudentAdmissionDate timestamp default CURRENT_TIMESTAMP    -> ); Query OK, 0 rows affected (0.55 sec)Following is the query to insert some records in the table using insert command −mysql> insert into defaultCurrent_DateDemo(StudentName) values('Larry'); Query OK, 1 row affected (0.52 sec) mysql> insert into defaultCurrent_DateDemo(StudentName, StudentAdmissionDate) values('Chris', '2019-01-31'); Query OK, 1 row affected (0.18 sec)Following is the ... Read More

Display a TreeSet in Reverse Order in Java

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

447 Views

To display a TreeSet in reverse order, you need to use Comparator. Let us first create an Integer array and use it for the TreeSet elements:Integer arr[] = { 25, 100, 125, 200, 250, 400, 450, 550, 600, 700};Now, use reverseOrde() comparator to reverse the natural ordering:Set set = new TreeSet(Collections.reverseOrder());Now, add individual elements of the set as the Integer array elements:for (int i = 0, l = arr.length; i < l; i++) {    set.add(arr[i]); }Exampleimport java.util.Collections; import java.util.Set; import java.util.TreeSet; public class Demo {    public static void main(String args[]) throws Exception {       Integer arr[] ... Read More

Get Records in a Certain Order Using MySQL

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

145 Views

You can use ORDER BY IF() to get records in a certain order. Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(20),    Branch varchar(20) ); Query OK, 0 rows affected (1.96 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(FirstName, Branch) values('John', 'CS'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(FirstName, Branch) values('Carol', 'ME'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable(FirstName, Branch) values('David', 'ME'); Query OK, 1 row affected (0.11 sec) mysql> ... Read More

FloatBuffer Array Method in Java

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

234 Views

A float array for the buffer can be obtained using the method array() in the class java.nio.FloatBuffer. If the returned array is modified, then the contents of the buffer are also similarly modified and vice versa. If the buffer is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          FloatBuffer buffer = FloatBuffer.allocate(n);          buffer.put(4.5F);          buffer.put(1.2F); ... Read More

Generate Parameters Method in Java

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

157 Views

The parameters can be generated using the method generateParameters() in the class java.security.AlgorithmParameterGenerator. This method requires no parameters and it returns the AlgorithmParameter object.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo {    public static void main(String[] argv) {       try {          AlgorithmParameterGenerator apGenerator = AlgorithmParameterGenerator.getInstance("DiffieHellman");          apGenerator.init(1024);          AlgorithmParameters aParameters = apGenerator.generateParameters();          System.out.println(aParameters);       } catch (NoSuchAlgorithmException e) {          System.out.println("Error!!! NoSuchAlgorithmException");       } catch (ProviderException e) ... Read More

Why is iostream EOF Inside a Loop Condition Considered Wrong

Chandu yadav
Updated on 30-Jul-2019 22:30:25

225 Views

The iostream::eof in a loop is considered as wrong because we haven’t reached the EOF. So it does not mean that the next read will succeed.When we want to read a file using file streams in C++. And when we use a loop to write in a file, if we check the end of file using stream.eof(), we are actually checking whether the file has reached end or not.Example Code#include #include using namespace std; int main() { ifstream myFile("myfile.txt"); string x; while(!myFile.eof()) { myFile >> ... Read More

Use NavigableSet Interface in Android

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

180 Views

This example demonstrates about How to use Navigable set interface in AndroidStep 1 &minus Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.                                 In the above code, we have taken the name and record number as Edit text, when the user clicks on save button it will store the data into ArrayList. Click on the refresh button to get ... Read More

Get Launcher Thumbnail Size in Android

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

164 Views

This example demonstrates How to get launcher thumbnail size in android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. In the above code, we have taken text view to show activity launcher thumbnail size.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.Context; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity ... Read More

MonthDay equals Method in Java

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

160 Views

The equality of two MonthDay objects can be determined using the equals() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object to be compared. Also it returns true if both the MonthDay objects are equal and false otherwise.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       MonthDay md1 = MonthDay.parse("--02-22");       MonthDay md2 = MonthDay.parse("--02-22");       System.out.println("The MonthDay md1 is: " + md1);       System.out.println("The MonthDay md2 is: " + ... Read More

Advertisements