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

Can a class have interface and vice-versa?
how its possible both has different meaning you cant enclosed it
Deepa
0 0
7
Is it possible to learn java at home without coaching in one month?
It all depends on you. If you are already aware of programming then it is definetly possible to learn java at home. But if learn through a tutor then you can learn easily.
Pritom
0 0
5
Can anyone know if there are tools/apps for representing the objects/classes/methods in the JVM in pictorial way?
rational rose and ibm software architect can be used for design and representation
Raghavendra Reddy
0 0
7

I am a fresher and I want to become a Java developer, so what is necessary to crack the Java interview ? 

For an interview, you should prepare all the basic questions of Java , class, function and OOP concepts.
Dipesh
Is there anyone who can teach Advance Java in minimal time and low cost?
2 weeks i can teach entire Core and Advanced JAVA ... But certification will not be given for this ..as am not organizing Batch
Garwita

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 Advantages
In this video, learn about Java and its advantages. Also, check out the difference between Java and C++, Java development kit, Java Run Time Environment (JRE) with a proper demonstration program for better clarity.


What Is Applet & Its Life Cycle?
What is Applet & its life cycle?Applet is a Java programme that can be embedded into HTML page.Java Applet runs on the java enables web browsers such as Mozilla & Internet Explorer.Applets are...
I

ICreative Solution

0 0
0

JAVA Online Training
What is Java? Java is a technology developed by James Gosling at Sun Microsystems, Sun Microsystems is now a part of Oracle Corporation. This is one of the most powerful & securable language used to...

Class, Object and Methods in JAVA
Lesson-1: Class, Object and Methods of Java can be compared with body, heart and brain. Without these 3 things, Java does not exist. If you Google the above 3 items, you will find many definitions. But...

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