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

How many classes will it take to learn core Java?
25-35 . depends on the student's previous knowledge on any programming languages
Gene
Who invented Java language?
James Gosling invented java language
Niranjan
I have the opportunity to learn either java or pega...what should i be targeting Pega or Java.. Also, if I m moving to Java. I will be getting immediate promotion and increment.
Java of course. You will see most of the enterprise level application are built in Java. Apart from retail, in every domain you'll see opportunity with Java
Gaurav
2 0
6
If a class contains only a private constructor and no other constructor, is it possible to create object of that class? If yes how?
Yes, It is possible. But, Object can be created only with in that class (either in any method or block).
Shabbir

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

Ask a Question

Related Lessons

Be prepared to get trained--init
Before starting the training,students must be mentally prepared for acceptance of new knowledge. Students must attend training with open minded forgetting the position they are working.This will help...
S

Smartnub Softsolutions

0 0
0

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.,...

Java Overview
Java platform overview Java platform components The Java platform consists of the following components. The Java language Like any programming language, the Java language has its own structure, syntax...
A

Akshay Shende

0 0
0

Java 8 Predicates
In the previous lession, we have learnt how to use filters and collectors. In filter we have passed the condition to evaluate whether the object is eligible to be filtered or not. Code given below for...

Constructor Overloading
public class ConstructorOverloading { public ConstructorOverloading(){ System.out.println("default"); } public ConstructorOverloading(String a){ System.out.println("a"); } public ConstructorOverloading(int...
S

Sarthak C.

0 0
0

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