Search for String or Number in a Field with MongoDB

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

985 Views

You can use $in operator for this. Let us first create a collection with documents −> db.searchForStringOrNumberDemo.insertOne(    {       "_id": new ObjectId(),       "StudentName": "Larry",       "StudentDetails": {          "StudentMarks": {             "StudentMongoDBMarks": [44]          }       }    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce2407c36e8b255a5eee944") } > db.searchForStringOrNumberDemo.insertOne( { "_id": new ObjectId(), "StudentName": "Larry", "StudentDetails": { "StudentMarks": { "StudentMongoDBMarks": ["44"] } } } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce240f036e8b255a5eee945") }Following is ... Read More

Drop a Table from JavaDB Using JDBC

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

206 Views

You can create a table in a database using the CREATE TABLE query.SyntaxCREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, PRIMARY KEY( one or more columns ) );To create a table in a database using JDBC API you need to −Register the driver − Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection − Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement − Create a Statement ... Read More

Efficiently Print All Prime Factors of a Given Number in C

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

756 Views

In this section, we will see how we can get all the prime factors of a number in an efficient way. There is a number say n = 1092, we have to get all prime factors of this. The prime factors of 1092 are 2, 2, 3, 7, 13. To solve this problem, we have to follow this rule −When the number is divisible by 2, then print 2, and divide the number by 2 repeatedly.Now the number must be odd. Now starting from 3 to square root of the number, if the number is divisible by current value, then ... Read More

Get Font Metrics in Java Swing

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

612 Views

To get the font metrics, use the FontMetrics class:Graphics2D graphics = (Graphics2D) gp.create(); String str = getWidth() + "(Width) x (Height)" + getHeight(); FontMetrics m = graphics.getFontMetrics();Now to display it:int xValue = (getWidth() - m.stringWidth(str)) / 2; int yValue = ((getHeight() - m.getHeight()) / 2) + m.getAscent(); graphics.drawString(str, xValue, yValue);The following is an example to get the font metrics in Java Swing:Exampleimport java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Font Metrics");       ... Read More

Map to Add String Value to Each Element in Java

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

860 Views

Let’s say the following is our String List −List list = Arrays.asList("Football", "Basketball", "Hockey", "Cricket", "Fencing");Now, map to add string to each element −List str = list.stream().map(name -> "Sports " + name + " Outdoor")    .collect(Collectors.toList());Above, we have added “Sports” and “Outdoor” strings to each element.The following is an example to Map and add string value to each element in Java −Exampleimport java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class Demo {    public static void main(String[] args) {       List list = Arrays.asList("Football", "Basketball", "Hockey", "Cricket", "Fencing");       List str = list.stream().map(name -> "Sports " ... Read More

Make a Background 25% Transparent on iOS

Anvi Jain
Updated on 30-Jul-2019 22:30:26

1K+ Views

Apple provides backgroundColor which is an instance property, Changes to this property can be animated. The default value is nil, which results in a transparent background color.To make background 25% transparent we should  set the view to the UIColor with alpha 0.25view.backgroundColor = UIColor(white: 1, alpha: 0.25)You can write the following code in your ViewController’s viewDidLoad method.Your code should look like below.override func viewDidLoad() {    super.viewDidLoad()    view.backgroundColor = UIColor(white: 1, alpha: 0.25) }

Format Text in JTextPane using Java

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

486 Views

To format text in JTextPane, use the SimpleAttributeSet and StyleConstants class. This allows you to set the style of text, background color, foreground color, etc.At first, create a new JTextPane −JTextPane pane = new JTextPane();Now, use the classes to set the style and color −SimpleAttributeSet attributeSet = new SimpleAttributeSet(); StyleConstants.setItalic(attributeSet, true); StyleConstants.setForeground(attributeSet, Color.black); StyleConstants.setBackground(attributeSet, Color.orange);Now, apply the set to the pane −pane.setCharacterAttributes(attributeSet, true);The following is an example to format text in JTextPane −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; public class SwingDemo {    public static void ... Read More

Detect Click on HTML Button through JavaScript in Android WebView

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

4K+ Views

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 assets/page.html           First name:       Last name:                function getValues() {             document.getElementById("btnOK").value =             document.getElementById("txtfname").value+"         ... Read More

Explain Polymorphism in PHP

Alok Prasad
Updated on 30-Jul-2019 22:30:26

13K+ Views

To begin with, Polymorphism is gotten from the Greek words Poly (which means many) and morphism (which meaning forms).Polymorphism portrays an example in object-oriented programming where methods in various classes that do similar things should have a similar name. Polymorphism is essentially an OOP pattern that enables numerous classes with different functionalities to execute or share a commonInterface. The usefulness of polymorphism is code written in different classes doesn't have any effect which class it belongs because they are used in the same way. In order to ensure that the classes do implement the polymorphism guideline, we can pick between ... Read More

MySQL Query to Get Current Date from List of Dates

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

162 Views

For the current day, you can use CURDATE() method. Let us first create a table −mysql> create table DemoTable    -> (    -> DueDate date    -> ); Query OK, 0 rows affected (1.35 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-06-14' ); Query OK, 1 row affected (0.35 sec) mysql> insert into DemoTable values('2019-06-15'); Query OK, 1 row affected (0.64 sec) mysql> insert into DemoTable values('2019-06-16'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2018-01-16'); Query OK, 1 row affected (0.29 sec) mysql> insert into ... Read More

Advertisements