UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Hi, Can anyone help me on below queries? 1. What makes a class as "Thread safe class" ? 2. equals() method uses 3. Difference between String vs StringBuffer ?

Asked by Last Modified  

26 Answers

Learn Java

Follow 1
Answer

Please enter your answer

String objects are immutable in java while in StringBuffer objects u can make changes like insert ,delete or append characters
Comments

Java/J2EE, B.E./B.Tech/MCA SubjectsTraining

String vs StringBuffer : 1) Mutability: String is immutable (Once created, cannot be modified) while StringBuffer is mutable (can be modified). 2) Performance: While performing concatenations you should prefer StringBuffer over String because it is faster. The reason is: When you concatenate strings...
read more
String vs StringBuffer : 1) Mutability: String is immutable (Once created, cannot be modified) while StringBuffer is mutable (can be modified). 2) Performance: While performing concatenations you should prefer StringBuffer over String because it is faster. The reason is: When you concatenate strings using String, you are actually creating new object every time since String is immutable. read less
Comments

Java/J2EE, B.E./B.Tech/MCA SubjectsTraining

equals() method compares string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object. public boolean equals(Object anObject)
Comments

Java/J2EE, B.E./B.Tech/MCA SubjectsTraining

There are three ways to construct thread-safe Java class which has some state: 1. Make it truly immutable 2.Make field volatile. 3.Use a synchronized block
Comments

Coaching

If you are creating a library of classes that will be used in both thread-safe and non-thread-safe requirements, consider making wrappers an option. equals() method: This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String...
read more
If you are creating a library of classes that will be used in both thread-safe and non-thread-safe requirements, consider making wrappers an option. equals() method: This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object. Syntax: public boolean equals(Object anObj) Parameters: anObj -- the object to compare this String against. Return Value : This method returns true if the String are equal; false otherwise. String vs StringBuffer: String is immutable whereas StringBuffer can change their values. String class is used to manipulate character strings that cannot be changed. Objects of type String are read only and immutable. The StringBuffer class is used to represent characters that can be modified. StringBuffer concatenation is significantly faster than String concatenation. read less
Comments

Professional Java Trainer

to make a class thread safe, use synchronization process equals() method is used to compare two objects
Comments

Programming expert

Strings are immutable and StringBuffer objects are mutable
Comments

Core Java Advanced Java NET GATE Computer Science

equals method is in Object class whose default implementation checks the memory location of the objects which is similar to ===. The String class has overridden the equals method and new implementation checks the string content present in the object. One has to override the hashcode(in Object class)...
read more
equals method is in Object class whose default implementation checks the memory location of the objects which is similar to ===. The String class has overridden the equals method and new implementation checks the string content present in the object. One has to override the hashcode(in Object class) method too when override the equals method. read less
Comments

Let's simplify Coding, It's a great Fun.

Hi, Thread Safe Class: If your class is exposed to concurrent threads then you need to device a policy to prevent multiple threads to access the class properties at the same time. (1) you can use intrinsic synchronized() blocking. (2) you can make property volatile. (3) you can use Atomic class. Equal() it...
read more
Hi, Thread Safe Class: If your class is exposed to concurrent threads then you need to device a policy to prevent multiple threads to access the class properties at the same time. (1) you can use intrinsic synchronized() blocking. (2) you can make property volatile. (3) you can use Atomic class. Equal() it is used to equate the references whether they point to same objects or not, this method is defined by Object class, if you are overriding equal() method in your class then you also need to override hashcode() method. String vs StringBuffer String is immutable object, that means once object is created you cannot change it, it has no setter() method. StringBuffer() is a mutable object, you can change its content after the object is created, means it provides setter() methods Vijay read less
Comments

Tutor

1.By making all methods in a class as synchronized, a class can become thread safe. 2.equals() method is to compare the content of object , in String, Wrapper classes(Integer,Double,etc) the equals() is overridden. If its a custom class, you need override the equals() and provide the code inside to...
read more
1.By making all methods in a class as synchronized, a class can become thread safe. 2.equals() method is to compare the content of object , in String, Wrapper classes(Integer,Double,etc) the equals() is overridden. If its a custom class, you need override the equals() and provide the code inside to compare the custom object. 3.String is immutable(means u cant change the String value), StringBuffer is immutable. String is not synchronized, and StringBuffer is Synchronized. read less
Comments

View 24 more Answers

Related Questions

What are the difference between abstract class and Interface?
Abstraction : Hiding unnecessary details of object and shows only essential features of Object to communicate. abstract class : partially defined Object interface :Complete specification of Object class : Complete definition of Object
Ashish
Is it possible to instantiate the abstract class?
Use anonymous class. Example: For an abstract class AbstrClass. AbstrClass ac = new AbstrClass() { public void m1() { // code...
Reshma

I am a fresher and I want to become a Java developer, so what is necessary to crack the Java interview ? 

Hi Dipesh, understand that Java is a kind of ocean. It is vast. For interview preparation, you can brush up your Core Java Concepts and OOPs concepts and understand how JAVA works and learn the java features...
Dipesh
I know HTML, CSS, and a bit of JavaScript. What should I learn next?
HTML,CSS and Javascript are Tools which are used for Front-End Web Development. The next step is to learn the following: 1)Learn Javascript Frameworks like node.js,react.js,angular.js etc. 2)Learn Back-End...
Inch By
Is it good to go for a Java coaching center and learn Java (with advanced Java) to improve my programming skills?
yes, Please check the Institute reviews and discuss with the tutor, what topics were covered in class. Ask about the practicals session and how many hours/duration of the course.
Gerda
0 0
5

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Lambda Expressions in Java
A lambda expression, introduced in Java 8 is similar to a block of code resembling an anonymous function that can be passed to constructors or methods for execution as an argument. Examples: a)() ->...


Java: A Quick Overview
Not purely Object Oriented: It doesn't support multiple inheritence, it supports primitive data types and static members. Doesn’t support multiple inheritance: Reason is diamond problem i.e.,...

1.2. Find the largest element in an array.
public class Main { public static void main(String args) { int arr = {1, 2, 3, 4, 5}; int max = arr; for (int i = 1; i < arr.length; i++) { if (arr > max) { max = arr; } } System.out.println("Largest Element: " + max); }}

Core Java
Introduction: An Object Oriented Programming Language consists of Objects. There are object oriented programming languages like Smalltalk, C++. Each and every OOP language has some underlying disadvantages....

Recommended Articles

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Java is the most famous programming language till date. 20 years is a big time for any programming language to survive and gain strength. Java has been proved to be one of the most reliable programming languages for networked computers. source:techcentral.com Java was developed to pertain over the Internet. Over...

Read full article >

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more