To find the highest value from sub-arrays in documents, you can use an aggregate framework. Let us first create a collection with documents> db.findHighestValueDemo.insertOne( ... { ... _id: 10001, ... "StudentDetails": [ ... { "StudentName": "Chris", "StudentMathScore": 56}, ... { "StudentName": "Robert", "StudentMathScore":47 }, ... { "StudentName": "John", "StudentMathScore": 98 }] ... } ... ); { "acknowledged" : true, "insertedId" : 10001 } > db.findHighestValueDemo.insertOne( ... { ... _id: 10002, ... "StudentDetails": [ ... Read More
To evaluate mathematical string to int, use Nashorn JavaScript in Java i.e. scripting. Nashorn invoke dynamics feature, introduced in Java 7 to improve performance.For scripting, use the ScriptEngineManager class for the engine:ScriptEngineManager scriptEngineManager = new ScriptEngineManager(); ScriptEngine scriptEngine = scriptEngineManager.getEngineByName("nashorn");Now, use put() to set a key/value pair in the state of the ScriptEngine:scriptEngine.put("one", 10); scriptEngine.put("two", 50); scriptEngine.put("three", 40);Now, here is the mathematical string. Use eval to evaluate:String strExp = "(one + two - three) == 20"; Object evalExp = scriptEngine.eval(strExp);Exampleimport javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; public class Demo { public static void main(String[] args) { ScriptEngineManager ... Read More
To calculate age from date of birth, you can use the below syntax −select timestampdiff(YEAR, yourColumnName, now()) AS anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentDOB datetime ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentDOB) values('1996-01-12'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(StudentDOB) values('1990-12-31'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentDOB) values('1989-04-01'); Query OK, 1 row affected (0.45 sec) mysql> insert into DemoTable(StudentDOB) values('2000-06-17'); Query ... Read More
The offset of the first element of the buffer inside the buffer array is obtained using the method arrayOffset() in the class java.nio.IntBuffer. If the buffer backed by the array 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 { IntBuffer buffer = IntBuffer.allocate(5); buffer.put(8); buffer.put(1); buffer.put(3); ... Read More
The provider of the key pair object can be obtained using the getProvider() method in the class java.security.KeyPairGenerator. This method requires no parameters and it returns the provider of the key pair 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 { KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("DSA"); Provider p = kpGenerator.getProvider(); System.out.println("The Provider is: " + p.getName()); } catch (NoSuchAlgorithmException e) { ... Read More
The PGM is the Portable Gray Map. If we want to store a 2d array in C as images in PNG, JPEG, or any other image format, we have to do lots of work to encode the data in some specified format before writing into a file.The Netpbm format gives an easy and portable solution. The Netpbm is an open source package of graphics program and it is used basically in linux or Unix platform. It also works under Microsoft Windows systems.Each file starts with a two-byte magic number. This magic number is used to identify the type of the ... Read More
This example demonstrates How to print list values in reverse order using Collections.reverse() 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 name and record number as Edit text, when user click on save button it will store the data into arraylist. Click on refresh button to get the ... Read More
The following URL will pass two values to HelloForm program using the GET method.href="http://localhost:8080/main.jsp?first_name=ZARA&last_name=ALI" Below is the main.jsp JSP program to handle input given by web browser. We are going to use the getParameter() method which makes it very easy to access the passed information − Using GET Method to Read Form Data Using GET Method to Read Form Data First Name: Last ... Read More
The fn:contains() function determines whether an input string contains a specified substring.SyntaxThe fn:contains() function has the following syntax −boolean contains(java.lang.String, java.lang.String)ExampleFollowing example explains the functionality of fn:contains() function − Using JSTL Functions Found test string Found TEST string You will receive the following result −Found test string
Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to use MAX() in Android sqlite.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create ... Read More