- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2617 Articles for Java
333 Views
A polygon with all the interior angles less than 180 is known as a convex polygon. The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc. To draw a polygon you need to invoke the fillConvexPoly() method of this class. This method accepts 3 parameters −A Mat object representing the image on which the polygon is to be drawn.A MatOfPoint object points between which the polygon is to be drawn.A Scalar object representing the color of the polygon.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfPoint; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class DrawingConvexPolygon { public ... Read More
136 Views
The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc this class provides various methods to process an input image. It provides a set of methods to draw geometrical shapes on images.To draw an arrowed line you need to invoke the arrowedLine() method of this class. This method accepts the following parameters −A Mat object representing the image on which the line is to be drawn.Two Point objects representing the points between which the line is to be drawn.A Scalar object representing the color of the line. (BGR)An integer representing the thickness of the line(default:1).Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; ... Read More
465 Views
The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc. This class provides a method named circle(), using this you can draw a circle on an image. This method provides the following parameters −A Mat object representing the image on which the circle is to be drawn.A Point object representing the center of the circle.An integer variable representing the radius of the circle.A Scalar object representing the color of the circle(BGR).An integer representing the thickness of the circle(default 1).If you pass Imgproc.FILLEDas line type, this method generates/draws a filled circle.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Scalar; import ... Read More
256 Views
If you try to read an image using the OpenCV imread() method it returns a Mat object. If you want to display the contents of the resultant Mat object using a JavaFX window You need to convert the Mat object to an object of the class javafx.scene.image.WritableImage. To do so, you need to follow the steps given below −Encode the Mat to MatOfByte − First of all, you need to convert the matrix to the matrix of a byte. You can do it using the method imencode() of the class Imgcodecs.This method accepts a String parameter(specifying the image format), a ... Read More
382 Views
The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc this class provies various methods such as, resize(), wrapAffine(), filter2D, to process an input image.In addition to them It provides a set of method to draw geometrical shapes on images, Following are some of them −ShapeMethod and DescriptionEllipseYou can draw an ellipse on an image using the ellipse() method.CircleYou can draw a circle on an image using the circle() method.RectangleYou can draw a rectangle on an image using the rectangle() method.PolygonYou can draw a polygon on an image using the polygon() method.LineYou can draw a line on an ... Read More
1K+ Views
Using the updateMany() method you can update all the documents of a collection.Syntaxdb.COLLECTION_NAME.update(, )In Java the com.mongodb.client.MongoCollection interface provides you a method with the same name. Using this method you can update multiple documents in a collection at once, to this method you need to pass the filter and values for the update.Exampleimport com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; import com.mongodb.client.model.Updates; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bson.Document; import org.bson.conversions.Bson; import com.mongodb.MongoClient; public class UpdatingMultipleDocuments { public static void main( String args[] ) { // Creating a Mongo client MongoClient mongo ... Read More
3K+ Views
The update() method updates the values in the existing document.Syntaxdb.COLLECTION_NAME.update(SELECTIOIN_CRITERIA, UPDATED_DATA)In Java, you can update a single document using the updateOne()method of the com.mongodb.client.MongoCollection interface. To this method, you need to pass the filter and values for the update.Exampleimport com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Filters; import com.mongodb.client.model.Updates; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bson.Document; import com.mongodb.MongoClient; public class UpdatingDocuments { public static void main( String args[] ) { // Creating a Mongo client MongoClient mongo = new MongoClient( "localhost" , 27017 ); //Connecting to the database ... Read More
1K+ Views
While retrieving records from a MongoDB collection, you can sort the records in the result using the sort() method.Syntaxdb.COLLECTION_NAME.find().sort({KEY:1})The Java MongoDB library provides a method with the same name, to limit the number of records invoke this method (on the result of the find() method) by passing the type of the sort (ascending or descending) and the field name based on which you want to sort the records as −sort(Sorts.ascending("age");Exampleimport com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Sorts; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bson.Document; import com.mongodb.MongoClient; public class SortingRecords { public static void main( String args[] ) { ... Read More
1K+ Views
There is no separate method to create a MongoDB database in Java, you can create a database by invoking the getDatabase() method of the com.mongodb.MongoClient class.Exampleimport com.mongodb.MongoClient; public class CreatingDatabase { public static void main( String args[] ) { //Creating a MongoDB client @SuppressWarnings("resource") MongoClient mongo = new MongoClient( "localhost" , 27017 ); //Accessing the database mongo.getDatabase("myDatabase1"); mongo.getDatabase("myDatabase2"); mongo.getDatabase("myDatabase3"); System.out.println("Databases created successfully"); } }OutputDatabases created successfully
2K+ Views
In MongoDB to create an index, you need to use createIndex() method.Syntaxdb.COLLECTION_NAME.createIndex({KEY:1})Where the key is the name of the file on which you want to create index and 1 is for ascending order. To create an index in descending order you need to use -1.In Java, you can create an Index using the createIndex() method, to this method you need to pass the type of the index (ascending or descending) and the field name on which you want to create the index, as −createIndex(Indexes.descinding("name"));Exampleimport com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Indexes; import org.bson.Document; import com.mongodb.MongoClient; public class CreatingIndex { public static void ... Read More