Dynamic Cast and Static Cast in C++

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

3K+ Views

static_cast: This is used for the normal/ordinary type conversion. This is also the cast responsible for implicit type coersion and can also be called explicitly. You should use it in cases like converting float to int, char to int, etc. This can cast related type classes. If the types are not same it will generate some error.Example#include using namespace std; class Base {}; class Derived : public Base {}; class MyClass {}; main(){    Derived* d = new Derived;    Base* b = static_cast(d); // this line will work properly    MyClass* x = static_cast(d); // ERROR will be generated ... Read More

BCD Numbers in 8085 Microprocessor

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

2K+ Views

Many a time, we are required to represent decimal numbers in a computer, and perform arithmetic on these numbers. For example, we may be required to total the marks a student has obtained in five different subjects, where obviously, the marks are awarded in decimal notation.For this purpose, the BCD code is extensively used. In BCD notation, 4 bits are used to code a digit, and so two digits of information are stored in a Byte. For example, decimal 45 is represented in BCD as of 0100 0101. Codes 10 to 15 i.e. 1010, 1011, 1100, 1101, 1110, and 1111 ... Read More

Get Phone Number in Android

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

5K+ Views

This example demonstrate about How to get phone number 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. When user open application, Phone number going to append on textview.Step 3 − Add the following code to src/MainActivity.java.package com.example.andy.myapplication; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.telephony.TelephonyManager; import android.widget.TextView; import ... Read More

Apply if Tag in JSP

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

274 Views

The tag evaluates an expression and displays its body content only if the expression evaluates to true.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaulttestCondition to evaluateYesNonevarName of the variable to store the condition's resultNoNonescopeScope of the variable to store the condition's resultNopageExample Tag Example My salary is: The above code will generate the following result −My salary is: 4000

LocalDate.now() Method in Java

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

272 Views

The current date can be obtained from the system clock in the default time zone using the now() method in the LocalDate class in Java. This method requires no parameters and it returns the current date from the system clock in the default time zoneA program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalDate ld = LocalDate.now(); System.out.println("The LocalDate is: " + ld); } }OutputThe LocalDate is: 2019-02-15Now let ... Read More

IntStream mapToDouble Method in Java

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

915 Views

The mapToDouble() method returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows.DoubleStream mapToDouble(IntToDoubleFunction mapper)Here, the parameter mapper is the stateless function applied to each element.Create an IntStream with some elements.IntStream intStream = IntStream.of(5, 20, 25, 45, 60, 75, 85, 90);Now, use the mapToDouble() method to return a DoubleStream.DoubleStream doubleStream = intStream.mapToDouble(val -> (double) val);The following is an example to implement IntStream mapToDouble() method in Java.Example Live Demoimport java.util.*; import java.util.stream.IntStream; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       IntStream intStream ... Read More

View Auto Increment Value for a Table in MySQL

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

2K+ Views

In order to view the auto_increment value for a table, you can use SHOW TABLE command.The syntax is as followsSHOW TABLE STATUS LIKE 'yourTableName'\GThe syntax is as followsSELECT `AUTO_INCREMENT`    FROM `information_schema`.`TABLES`    WHERE `TABLE_SCHEMA` = ‘yourDatabaseName’    AND `TABLE_NAME` =’yourTableName';To understand the above syntaxes, let us create a table. The query to create a table is as followsmysql> create table viewAutoIncrementDemo    -> (    -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserName varchar(20)    -> ); Query OK, 0 rows affected (0.59 sec)Now you can insert some records in the table using insert command. The ... Read More

Check Sub-tree of a Binary Tree in C++

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

249 Views

A binary tree is a tree data structure in which each node has at most two children, which are defined as left child and right child.AlgorithmBegin    function identical():        Take two nodes r1 and r2 as parameter.       If r1 and r2 is NULL then          Return true.       If r1 or r2 is NULL then          Return false.       Return (r1->d is equal to r2->d and          Call function Identical(r1->l, r2->l) and          Call functions Identical(r1->r, r2->r) ); ... Read More

Update Value of a Key in a List of JSON in MongoDB

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

767 Views

Let us first create a collection with documents> db.updateListOfKeyValuesDemo.insertOne( { "StudentDetails":[ { "StudentName":"John", "StudentAge":23, "StudentCountryName":"US" }, { "StudentName":"Carol", "StudentAge":24, "StudentCountryName":"UK" }, { "StudentName":"Bob", "StudentAge":22, "StudentCountryName":"AUS" } ] } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b5b759882024390176545") }Following is the query to display all documents from a collection with the help of find() method> db.updateListOfKeyValuesDemo.find().pretty();This will produce the following output{    "_id" : ObjectId("5c9b5b759882024390176545"),    "StudentDetails" : [       {          "StudentName" : "John",          "StudentAge" : 23,          "StudentCountryName" : "US"       },     ... Read More

Generate Random BigInteger Value in Java

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

3K+ Views

To generate random BigInteger in Java, let us first set a min and max value −BigInteger maxLimit = new BigInteger("5000000000000"); BigInteger minLimit = new BigInteger("25000000000");Now, subtract the min and max −BigInteger bigInteger = maxLimit.subtract(minLimit); Declare a Random object and find the length of the maxLimit: Random randNum = new Random(); int len = maxLimit.bitLength();Now, set a new B integer with the length and the random object created above.Example Live Demoimport java.math.BigInteger; import java.util.Random; public class Demo {    public static void main(String[] args) {       BigInteger maxLimit = new BigInteger("5000000000000");       BigInteger minLimit = new BigInteger("25000000000");   ... Read More

Advertisements