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

best source to learn java from?
Main source if information on Java is oracle documentation. But it takes your time to read through, a lot more than you expect. Better prefer a trainer who can give what you need.
Himanshu
What exactly the work of constructor( default, parameterized) especially about instance variables initialization. Suppose user initialize the instance variables explicitly. Then what is the use of parameterized constructor over here.. Please reply me
Constructor is used to initialize an object at the time of creation. A default constructor is provided by the compiler itself if no constructor is provided by the user. It initializes the state of the...
Surekha
What is the difference between Java SE, ME, EE?
Java SE is Standard Edition of Java, also known as Core Java. Anybody who wants to work with Java must learn this. And, this is used to write stand alone software with Java. . Java ME is the Micro Edition...
Sense Softech
0 0
5
What is the general syllabus covered in core Java training from any institution?
Welcome Course Overview Review of Java Fundamentals The Java Environment Data Types The String Class The StringBuffer Class Arrays Passing Data Types to a Method Constructors &...
Shiv Kohli
0 0
5
Is it really needed to do Java training before graduation, to get a job?
Yes, It's must to get better opportunities and to standard alone in IT field. Not only core Java but also learn Spring,Hinernat ,Struts. ANGULARJS add an advantage to get job easily.
Udaybhan

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

Ask a Question

Related Lessons

1.1. Reverse an array in Java.
public class Main { public static void main(String args) { int arr = {1, 2, 3, 4, 5}; for (int i = 0; i < arr.length / 2; i++) { int temp = arr; arr = arr; arr = temp; } System.out.println(Arrays.toString(arr)); }}

Most Important Java Interview Topics
Dear All, I am here to help on java interview preparation for fresher and experienced people, please get in touch with me for further details. All interview preparation will be with unique teaching style...

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

How to create Rest web services in Java
Web services are web application components that lets two different applications to communicate over the network.Let if an application which in written java provides web services can be communicated through...

1.3. Find the second largest element in an array.
public class Main { public static void main(String args) { int arr = {1, 3, 4, 6, 5}; int max = Integer.MIN_VALUE, secondMax = Integer.MIN_VALUE; for (int i = 0; i < arr.length; i++) { if (arr >...

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