How do we copy objects in java?

Venkata Sai
Updated on 30-Jul-2019 22:30:26

8K+ Views

In Java you can copy an object in several ways, among them, copy constructor and the clone method are the mostly used.Using copy constructorGenerally, the copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. Java does support for copy constructors but you need to define them yourself.ExampleIn the following Java example, we a have a class with two instance variables name and age and a parameterized constructor initializing these variables.Then, we have another constructor which accepts an object of the current class and initializes the ... Read More

HTML DOM Input Number stepUp() Method

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

65 Views

The DOM input number stepUp() method increments the value of input number field by a specified value.SyntaxFollowing is the syntax −object.stepUp(number)Here, if number parameter is omitted then it increments the value by 1.ExampleLet us see an example of HTML DOM input number stepUp() method − Live Demo HTML DOM stepUp()/stepDown() Demo    body{       text-align:center;       background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%)       center/cover no-repeat;       height:100vh;       color:#fff;    }    p{       font-size:1.5rem;    }    input{       width:40%; ... Read More

HTML DOM links Collection

AmitDiwan
Updated on 30-Jul-2019 22:30:26

118 Views

The links Collection returns a list/collection of all the links corresponding to and/or elements.SyntaxFollowing is the syntax −Returning links collectiondocument.linksPropertiesHere, “links” collection can have the following properties and methods −Property/MethodDescriptionlengthIt returns the number of  and  elementsnamedItem()It returns the  or/and  element with the specified idExampleLet us see an example for links collection length property − Live Demo Links Collection length    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {   ... Read More

Functions that can’t be overloaded in C++

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

240 Views

In C++, we can overload the functions. But sometimes the overloading is not done. In this section, we will see what are the different cases, in which we cannot overload the functions.When function signatures are same, only the return type is different, then we cannot overload the function.int my_func() {    return 5; } char my_func() {    return 'd'; }When the member functions have the same name and same parameter list in a class, then they cannot be overloaded.class My_Class{    static void func(int x) {       //Something    }    void func(int x) {     ... Read More

C++ Program to Find number of Ways to Partition a word such that each word is a Palindrome

Smita Kapse
Updated on 30-Jul-2019 22:30:26

128 Views

Here we shall discuss a C++ Program to find number of ways to Partition a word in such a way that each word is a Palindrome.AlgorithmsBegin    Take the word as input.    Function partitionadd(vector &u, string &s, vector &tmp, int index):    if (index == 0)       tmp.clear()    for i = index to length-1       st = st + s[i]       if (checkPalin(st))          tmp.push_back(st)          if (i+1 < length)             partitionadd(u, s, tmp, i+1)          else   ... Read More

Resilient Packet Ring (RPR) - IEEE 802.17

Moumita
Updated on 30-Jul-2019 22:30:26

1K+ Views

Resilient Packet Ring (RPR), standardized as IEEE 802.17, is a protocol standard for data transmission over fiber optic ring networks, that operates in the Media Access Control (MAC) layer of the Open Systems Interconnection (OSI) model. It provides a packet based transmission facility, with the aim of improving efficiency of Ethernet and IP services. RPR provides improved bandwidth utilization and throughput, greater speed of deployment, and optimized equipment and operational costs.Working PrincipleThe stations in a RPR are connected by dual counter rotating fiber optic rings called ringlets. Transmission occurs along both the rings. This helps to utilize the total available ... Read More

Where to use a StringBuffer/StringBuilder than a String in Java?

raja
Updated on 30-Jul-2019 22:30:26

186 Views

The String class objects are immutable whereas the StringBuffer and the StringBuilder objects are mutable.A StringBuffer is synchronized while a StringBuilder is not synchronized.A Concatenation operator "+" is internally implemented using either StringBuffer or StringBuilder.If the Object value is not going to change use String Class because a String object is immutable.If the Object value can change and will only be accessed from a single thread, use a StringBuilder because StringBuilder is unsynchronized.If the Object value can change and will be modified by multiple threads, use a StringBuffer because StringBuffer is synchronized.

How to disable close button on a JFrame in Java?

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

688 Views

To disable the close button, let us first create a frame −JFrame frame = new JFrame("Login!");Use the setDefaultCloseOperation() to set the status of the close button. Set it to DO_NOTHING_ON_CLOSE to disable it −frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);The following is an example to disable close button on a JFrame in Java −Examplepackage my; import java.awt.GridLayout; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; import javax.swing.SwingConstants; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Login!");       JLabel label1, label2, label3;       frame.setLayout(new GridLayout(2, 2));       label1 = ... Read More

Concatenate fields in MongoDB?

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

265 Views

To concatenate fields, use the $concat operator. Let us first create a collection with documents −>db.concatenateFieldsDemo.insertOne({"StudentFirstName":"Adam", "StudentLastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6ebf46d78f205348bc62e") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Doe"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6ebfc6d78f205348bc62f") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6ec376d78f205348bc630") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"Sam", "StudentLastName":"Williams"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd6ec436d78f205348bc631") }Following is the query to display all documents from a collection with the help of find() method −> db.concatenateFieldsDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd6ebf46d78f205348bc62e"),    "StudentFirstName" : "Adam",    "StudentLastName" : "Smith" } ... Read More

HTML canvas strokeRect() Method

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

303 Views

The strokeRect() method of the HTML canvas is used to create a rectangle on a web page. 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.strokeRect(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 strokeStyle property of canvas ... Read More

Advertisements