Explain Equals Method of Object, String, and StringBuffer Classes

Narasimha Murthi
Updated on 29-Jun-2020 15:00:03

4K+ Views

To compare two objects the object class provides a method with name equals(), this method accepts an object and compares it with the current object. If the references of these two objects are equal, then it returns true else this method returns false.ExampleIn the following example we have a class Employee with two variables name, age and a parameterized constructor.From the main method we are creating two objects by passing same values and, comparing both values using the equals() method.Since the equals() method of the Object class returns true only if the references of the two objects are equal, this ... Read More

Difference Between Object and Reference in Java

Narasimha Murthi
Updated on 29-Jun-2020 14:58:28

11K+ Views

A class in a blue print/user defined datatype in java that describes the behavior/state that the object of its type support.Examplepublic class Student {    String name "Krishna";    int age = 20;    void greet() {       System.out.println("Hello how are you");    } }An object is an instance of a class created from it using the new keyword. Once you create an object of a class, using it you can access he members of the class. In the below given code an object of the class Student is created.public class Example {    public static void main(String ... Read More

Use Thread getName and setName in Android

Nishtha Thakur
Updated on 29-Jun-2020 14:58:25

319 Views

Before getting into example, we should know what thread is. A thread is a lightweight sub-process, it going to do back ground operations without interrupt to ui. This example demonstrate about How to use thread.getName() and thread.setName() 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 edit text and text view. When user enter some text into edit text, it ... Read More

Finalize Method Invocation in Java

Narasimha Murthi
Updated on 29-Jun-2020 14:57:55

1K+ Views

The finalize() method belongs to the Object class. Right before closing an object, the garbage collector makes sure that there are no more references to it and, calls the finalize() method on it.Therefore, once you override the finalize() method in it, you can do all the cleanup activity like closing the resources like database connection, network connection, etc.protected void finalize throws Throwable{}It is invoked only once during the execution of a program.Following are some notable points about the finalize method.Since this method belongs the Object class, which is the super class of all the classes in java, you can override ... Read More

Set the Priority for a Thread in Android

Anvi Jain
Updated on 29-Jun-2020 14:57:41

889 Views

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do background operations without interrupt to ui. This example demonstrate about How to use set the priority for a thread 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 edittext and textview. When user enter some text into edittext, it ... Read More

Pass Objects as an Argument in Java

Narasimha Murthi
Updated on 29-Jun-2020 14:57:14

10K+ Views

Yes, you can pass objects as arguments in Java. Consider the following example: Here we have a class with name EmployeeExampleIn the following Java example, we a have a class with two instance variables name and age and a parameterized constructor initializing these variables.We have a method coypObject() which accepts an object of the current class and initializes the instance variables with the variables of this object and returns it.In the main method we are instantiating the Student class and making a copy by passing it as an argument to the coypObject() method. Live Demoimport java.util.Scanner; public class Student {   ... Read More

Use Multiple Threads in Android

Smita Kapse
Updated on 29-Jun-2020 14:57:05

3K+ Views

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do background operations without interrupt to ui. This example demonstrate about How to use multiple threads 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 edittext and textview. When user enter some text into edittext, it going to ... Read More

Override Equals Method in Java

Narasimha Murthi
Updated on 29-Jun-2020 14:56:35

3K+ Views

To compare two objects the object class provides a method with name equals(), this method accepts an object and compares it with the current object. If the references of these two objects are equal, then it returns true else this method returns false.ExampleIn the following example we have a class Employee with two variables name, age and a parameterized constructor.From the main method we are creating two objects by passing same values and, comparing both values using the equals() method.Since the equals() method of the Object class returns true only if the references of the two objects are equal, this ... Read More

Use Thread.sleep() in Android

Nishtha Thakur
Updated on 29-Jun-2020 14:56:28

5K+ Views

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do background operations without interrupt to ui. This example demonstrate about How to use thread.sleep() 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 edittext and textview. When user enter some text into edittext, it going to wait till 5000ms ... Read More

Create a Thread in Android

Anvi Jain
Updated on 29-Jun-2020 14:55:50

6K+ Views

Before getting into an example, we should know what thread is. A thread is a lightweight sub-process, it going to do background operations without interrupt to ui. This example demonstrate about How to create a thread 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 edittext and textview. When user enter some text into edittext, it going to wait till ... Read More

Advertisements