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 0
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

hat is java
Java is high level programming language. Java is platform independent and robust.
Narendra
0 1
8
Should we learn DBMS and RDBMS without any Java training?
java or i can say any programming language is not required to learn DBMS or RDBMS
Karthik
0 0
6
Can I build iPhone apps using Python?
Yes, you can use PyMob app where apps can be written purely in Python, and the compiler tool flow converts them in native source codes for various platforms. But there are some cons on using PyMob, the...
Sunil
0 0
5
Which is the best IDE to write Java code?
Eclipse and intellige are the best IDE to write Java Code.
Akash
Does Java support pointers?
Yes and no. . The pointer model is of course supported by Java. But it has become much easier to the developer to handle it. Because Java exposes the concept of pointer in terms of reference variables...
Santosh
0 0
7

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

Ask a Question

Related Lessons

Tips of learning Java Language/Other Programming Languages
1.You should know the basic concept: If we talk about programming languages so basic concept are same in all the high level languages. So you should know the basic concept firstly then you can easily understand...
I

ICreative Solution

0 0
0

Finding a Majority Element
Problem Description Task. The goal in this code problem is to check whether an input sequence contains a majority element. Input Format. The first line contains an integer, the next one contains a sequence...

What Are IT Industries Performance Metrics?
1. Outstanding Expectation: Eligible to get Promotion easily and good salary hike. Always preferrable to go abroad. 2. Exceed Expectation: Can get Promotion as per schedule of company with good salary...

Why Should We Learn Java Language?
Most of starters has confusion today that which of the programming language should be chosen to work on. It totally depends upon your need. As per my opinion, if you want to grow your career in IT industry...

Design Pattern
Prototype Design Pattern: Ø Prototype pattern refers to creating duplicate object while keeping performance in mind. Ø This pattern involves implementing a prototype interface which tells...

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