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

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

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

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

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

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

1.Defining the threading model for your application is probably the most important step you can take into making your code thread safe.You need to have your threading model down beforehand so you can actually get your code right. The reason for that is that there are a lot of different ways to make your...
read more
1.Defining the threading model for your application is probably the most important step you can take into making your code thread safe.You need to have your threading model down beforehand so you can actually get your code right. The reason for that is that there are a lot of different ways to make your class thread safe, and you can only pick the right one if you know the thread access pattern to your class. 2.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. 3.------------------------------------------------------------------------------- String StringBuffer ---------------------------------------------------------------------------------- Storage Area Constant String Pool Heap Modifiable No (immutable) Yes( mutable ) Thread Safe Yes Yes Performance Fast Very slow ----------------------------------------------------------------------------------- read less
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

Experienced IT Trainer/Coach, Founder Win Corporate Training, Counsellor

String class is used create the immutable strings in Java. For Example: String str=new String("Good"); - If I want to add the word "Morning" I have to recreate my String class Object. String str=new String("Good Monring"); StringBuffer is used to create the Mutable Strings in Java StringBuffer...
read more
String class is used create the immutable strings in Java. For Example: String str=new String("Good"); - If I want to add the word "Morning" I have to recreate my String class Object. String str=new String("Good Monring"); StringBuffer is used to create the Mutable Strings in Java StringBuffer str1=new StringBuffer("Good"); str1.append("Monring"); We can add the new word without creating the object of the String class. read less
Comments

Software Engineer

1. What makes a class as "Thread safe class"? Thread safe class: If your class is being accessed by multiple threads then there is a possibility that class variable/properties may be accessed or changed by two or more thread simultaneously which may result in inconsistent behaviour of class. The process...
read more
1. What makes a class as "Thread safe class"? Thread safe class: If your class is being accessed by multiple threads then there is a possibility that class variable/properties may be accessed or changed by two or more thread simultaneously which may result in inconsistent behaviour of class. The process of preventing this is called as Thread safe. Process to make class thread safe: Use Synchronized Methods/blocks to prevent access of class properties by multiple threads. Use of Volatile keyword so that properties changed by one thread will immediately reflect to all other places. 2. equals() method uses equals method is used in Java to equate different Objects of Class. 3. Difference between String vs StringBuffer? String is immutable while StringBuffer is mutable. Mutable means state of object can be changed, while state of immutable can not be altered. read less
Comments

StringBuffer outdated , use StringBuilder thread safe,
Comments

View 24 more Answers

Related Questions

What is the difference between checked and unchecked exceptions?
The main difference between checked and unchecked exception is that the checked exceptions are checked at compile-time while unchecked exceptions are checked at runtime
Wren
What are the booming technologies in US from Job point of view
All the terminologies are good. First of all decide your self you want go as functional consultant or technical. If you have java background Learn Hadoop. Billing rate is very high.
Chandra
What is IBM RAD(Rational Application Developer)?
RAD means Rational Application Developer for WebSphere Software accelerates the development and deployment of Java, Java EE, Web 2.0, mobile, OSGi, portal and service-oriented architecture (SOA) applications....
Ashish
Which holds the future: Java or Python?
The future success of Java or Python depends on various factors, including industry trends, project requirements, and developer preferences. Both languages are widely used, with Java being prominent in...
Nikhil
0 0
5
What are the best websites to learn java as well as get a certificate from them?
To learn basic java i suggest javatpoint is good for knowledge as well as concept but for certification refer book
Abirami
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

Try to clear up the basics, if basics are clear then you can go ahead with any difficult problem
Hey guys, To all the students i just want to convey that just clear up your basics so that they can help you solve anyu problem and you would achieve a great success. Regards, Ishani Chakraborty

Session Tracking In Java Servlets
Session Tracking: HTTP is a stateless protocol. Each request is independent of the previous one. However, in some applications, it is necessary to save state information so that information can be collected...


Class and Objects in Java
Class is a template or a blueprint which is used to describe an object. On other hand Object is a reference of a class which follows all the stuff written inside the class. How about taking the whole tour in the following video

Example of DependsOnMethod in TestNG
public class dependsonM { @Test public void login() { System.out.println("login"); } @Test (dependsOnMethods = {"login"}) public void email() { //Intentionally I am failing this testcase Assert.assertTrue(false);...
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