The rect() method of the HTML canvas is used to create a rectangle. The element allows you to draw graphics on a web page using JavaScript. Every canvas has two elements that describes the height and width of the canvas i.e. height and width respectively.Following is the syntax −context.fillRect(p, q, width, height);Above, p: The x-coordinate of the upper-left corner of the rectangleq: The y-coordinate of the upper-left corner of the rectanglewidth: Width of the rectangleheight: Height of the rectangleLet us now see an example to implement the rect() method of canvas −Example Live Demo Your browser does ... Read More
Let’s say we are creating a database “web” −mysql> SHOW CREATE DATABASE web;This will produce the following output displaying the default charset as well −+----------+-----------------------------------------------------------------------------------------+ | Database | Create Database | +----------+-----------------------------------------------------------------------------------------+ | web | CREATE DATABASE `web` /*!40100 DEFAULT CHARACTER SET utf8 COLLATEutf8_unicode_ci */ | +----------+-----------------------------------------------------------------------------------------+ 1 row in set (0.03 sec)If you want to know ... Read More
You can convert a character to upper case using the toUpperCase() method of the character class.ExampleFollowing program converts alternate characters of a string to Upper Case. Live Demoimport java.util.Scanner; public class UpperCase { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a string :"); String str = sc.nextLine(); str = str.toLowerCase(); char[] ch = str.toCharArray(); for(int i=0; i
The HTML DOM removeNamedItem() method removes the node specified in its parameter from an attribute node using its name in an HTML document.SyntaxFollowing is the syntax −node.removeNamedItem(node);ExampleLet us see an example of removeNamedItem() method − Live Demo html{ height:100%; } body{ text-align:center; color:#fff; background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) center/cover no-repeat; height:100%; } .btn{ background:#0197F6; border:none; height:2rem; border-radius:2px; width:60%; margin:2rem ... Read More
Sometimes we need to know that, what is the current C++ standard. To get this kind of information, we can use the macro called __cplusplus. For different standards, the value of this will be like below.Standard__cplusplus outputC++ pre C++981C++98199711LC++98 + TR1This cannot be checked, this will be marked as C++98C++11201103LC++14201402LC++17201703LExample#include int main() { if (__cplusplus == 201703L) std::cout
Auto layout is constraint based layout system used for development of User Interfaces for iOS Devices. This layout based constraint system also known as Auto Layout is basically an adaptive UI which adapts to screens of different sizes and orientations.Auto layout is completely dependent on constraints where developer defines a relation between neighbouring or parent element to seize it position.Why Auto Layout?While designing an iOS application you need to make sure, the UI which you’re developing should be equally compatible with all screen sizes and orientation. Auto layout comes handy when you wish to do so.Consider below images. A centrally ... Read More
For background and foreground color of the JTextPane, use the following −JTextPane textPane = new JTextPane(); textPane.setBackground(Color.blue); textPane.setBackground(Color.green);For font face, style and size, use the Font class and set the font −Font font = new Font("Serif", Font.ITALIC, 18); textPane.setFont(font);The following is an example to set font, style and color for text in JTextPane −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.Font; 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.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; public class SwingDemo { public static void main(String args[]) throws BadLocationException { JFrame frame = new JFrame("Demo"); ... Read More
In the Real time world javascript doesn't have traditional classes as seen in other languages. It has objects and constructors. Object.freeze() is one among many constructor methods helps to freeze an object.Freezing an object does not allow new properties to be added to the object and also prevents the object from changing its own properties. Object.freeze() will always try to preserve the enumerability, configurability, writability and the prototype of the object. It won't create a frozen copy.Applications1) freeze() is used for freezing objects and arrays.2) freeze() is used to make an object immutable.SyntaxObject.freeze(obj)ExampleLive Demo // an object is created ... Read More
For this, use the $addToSet operator. Let us first create a collection with documents −> db.findDocumentWithCommonFieldsDemo.insertOne( { "UserId":1, "UserName":"Carol" } ); { "acknowledged" : true, "insertedId" : ObjectId("5cdf8ebebf3115999ed51200") } > db.findDocumentWithCommonFieldsDemo.insertOne( { "UserId":2, "UserName":"David" } ); { "acknowledged" : true, "insertedId" : ObjectId("5cdf8ebebf3115999ed51201") } > > db.findDocumentWithCommonFieldsDemo.insertOne( { "UserId":1, "UserName":"Sam" } ); { "acknowledged" : true, "insertedId" : ObjectId("5cdf8ebebf3115999ed51202") }Following is the query to display all documents from a collection ... Read More
The ResultSetMetadata class provides various methods that gives information about the current ResultSet object such as number of columns, name of the table, name of the column, datatype of the column etc…To prepare a CREATE query you need to get −Name of the table, using the getTableName() method.Column count, to iterate the columns using the getColumnCount() method.Name of the each column using the getColumnName() method.Data type of each column using the getColumnTypeName() method.Precision of each column using the getPrecision() method.ExampleLet us create a table with name customers in MySQL database using the CREATE query as shown below −CREATE TABLE Customers ... Read More