This example demonstrate about How to turn Android device screen on and off programmatically.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 Step 3 − Add the following code to res/xml/policies.xml Step 4 − Add the following code to src/DeviceAdminpackage app.tutorialspoint.com.sample ; import android.app.admin.DeviceAdminReceiver ; import android.content.Context ; import android.content.Intent ; import android.widget.Toast ... Read More
For this, use the aggregate framework. Let us first create a collection with documents −> db.aggregateArrayDemo.insertOne( { "_id":100, "UserDetails": [ { "UserName": "John", "UserLoginYear":2010 }, { "UserName": "Carol", "UserLoginYear":2019 } ] } ); { "acknowledged" : true, "insertedId" : 100 }Following is the query to display all documents from a collection with the help of find() method −> db.aggregateArrayDemo.find().pretty();This will produce the following output −{ "_id" : 100, "UserDetails" : [ { "UserName" : "John", "UserLoginYear" : 2010 }, { "UserName" : "Carol", "UserLoginYear" : 2019 } ] }Following is the query to aggregate array documents −> db.aggregateArrayDemo.aggregate([ { $match: { _id: 100 } }, { $project: { Minimum: { $min: "$UserDetails.UserLoginYear" }, Maximum: { $max: "$UserDetails.UserLoginYear" } } } ]);This will produce the following output −{ "_id" : 100, "Minimum" : 2010, "Maximum" : 2019 }
The java.sql.DriverManager class manages JDBC drivers in your application. This class maintains a list of required drivers and load them whenever it is initialized.Therefore, you need to register the driver class before using it. However, you need to do it only once per application.One way to register a driver class object to Driver manager is the registerDriver() method of the DriverManager class. To this method you need to pass the Driver object as a parameter.//Instantiating a driver class Driver driver = new com.mysql.jdbc.Driver(); //Registering the Driver DriverManager.registerDriver(driver);List of all the DriversYou can get the list of all the drivers registered ... Read More
The HTML DOM Input URL pattern property sets/returns the regular expression corresponding to URL Input. The pattern attribute’s value is checked against the text typed in url field.SytaxFollowing is the syntax −Returning regular expressioninputURLObject.patternSetting pattern to regular expressioninputURLObject.pattern = ‘RegExp’ExampleLet us see an example of Input URL pattern property − Live Demo Input URL pattern form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="submit"] { border-radius: 10px; ... Read More
If some function has no return type, then the return type will be int implicitly. If return type is not present, then it will not generate any error. However, C99 version does not allow return type to be omitted even if it is int.Example#include my_function(int x) { return x * 2; } main(void) { printf("Value is: %d", my_function(10)); }OutputValue is: 20
At first, we have set the stream −Stream.of(3.5, 4.7, 7.9, 8.2, 9.1, 10.5, 12.3, 15.8)Now to Map double to int Object, use mapToObj −.mapToInt(Double::intValue) .mapToObj(a -> "val" + a)The following is an example to Map double to int Object with mapToInt and mapToObj −Exampleimport java.util.stream.Stream; public class Demo { public static void main(String[] args) throws Exception { Stream.of(3.5, 4.7, 7.9, 8.2, 9.1, 10.5, 12.3, 15.8) .mapToInt(Double::intValue) .mapToObj(a -> "val" + a) .forEach(System.out::println); } }Outputval3 val4 val7 val8 val9 val10 val12 val15
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Number int ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Number) values(10); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Number) values(50); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(Number) values(100); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable(Number) values(190); Query OK, 1 row affected (0.12 sec)Display all ... Read More
To replace the first 10 character in text area, use the replaceRange() method in Java and replace the old text with the new text.Let’s say the following is oude demo text set with JTextArea −JTextArea textArea = new JTextArea("This is a text displayed for our example. We have replaced some of the text.");Now, replace the characters in a range −int begn = 0; int end = 10; // replace textArea.replaceRange("Replaced! ", begn, end);The following is an example to replace the first 10 charactrers in JTextArea −Examplepackage my; import java.awt.GridLayout; import javax.swing.*; public class SwingDemo { SwingDemo() { ... Read More
This example demonstrate about How to lock the Android device programmatically.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 Step 3 − Add the following code to src/MainActivitypackage app.tutorialspoint.com.sample ; import android.content.Intent ; import android.net.Uri ; import android.os.Bundle ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; public class MainActivity extends AppCompatActivity { @Override protected void onCreate (Bundle savedInstanceState) { super .onCreate(savedInstanceState) ; setContentView(R.layout. activity_main ) ... Read More
To return specific fields, use aggregate $project. Let us first create a collection with documents −> db.returnSpecificFieldDemo.insertOne( { "StudentId":1, "StudentDetails": [ { "StudentName":"Larry", "StudentAge":21, "StudentCountryName":"US" }, { "StudentName":"Chris", "StudentAge":23, "StudentCountryName":"AUS" } ] } ); { "acknowledged" ... Read More