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

Why is finally introduced in Java?
finally is block which executes every time regardless exception has occurred or not. Finally is important in case you want to do some task which must be done like clean-up, db connection closure, memory de-allocation etc.
Agastya
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
Is Java a pure object-oriented programming language?
Java is often considered to be a "pure" object-oriented programming (OOP) language because it follows many principles of OOP. However, it does have some features that deviate from strict purity. For example,...
Shiv
0 0
5
What are the core concepts of Java?
OOPs, Flow control, String Handling, generics, exception, threading, collection, IO, JDBC are some core concepts of Java.
Manish
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

Java
Java is a high level language which is far better than procedural languages like C, Fortran and Pascal. Java completely stands with the principles of OOPS (Object Oriented Programming Structure). The...
A

Abhisheak Saxena

0 0
0

Software Development Training In Jaipur
Satyam Web Solution provides website designing &development and software designing &development training in Jaipur for various stream’s students. MCA 6 month Industrial Training/Internship B....

Overloading in JAVA
When a class contains more than one method with the same method name but different argument types, then it is called Overloading. Methods are said to be Overloaded methods. Also, know as Compile time...

Final, Finally And Finalize In Java
Final: 1. It is a non access modifier that can be applied to variables,methods and to class. 2. Final means non-changable. Final variable: 1. If a variable is declared as final it can't be re-assigned. 2....

Comparable vs Comparator
java.lang.Comparable java.util.Comparator For comparing some other object with its own object. Ex. I am comparing myself to some other employee. Method signature is: int compareTo (T object). For...

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