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 reflection and what is its use in Java?
to inspect classes, interfaces, fields and methods at runtime, without knowing the names of the classes, methods etc. at compile time
Rahul
0 0
7
Does Java support pointers?
Yes and no. . The pointer model is of course supported by Java. But it has become much easier to the developer to handle it. Because Java exposes the concept of pointer in terms of reference variables...
Santosh
0 0
7
hi this iz sunil here I done with my b.sc in cs and planning to go fr java course shld I prefer for institution or a lecturer who teaches java at his own tuitions ...
i can teach you java the way you can play with real world thinking you don't need of knowledge of any other language. you can directly learn java
Sunil
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

Overview on Auto IT and use in selenium webdriver
AutoIt v3 is a freeware BASIC-like scripting languages designed for automating the windows GUI and general scripting. It used a combination of simulated keystrokes, mouse movements and window/control manipulation...
S

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

Final modifier in Java
Can’t change value of variable if marked as final. It is best practice to mark method parameter as final if its value will not changes. Variable must be initialize either using Initializer block...

Inheritance In Java
Inheritance: The process of getting properties and behaviors from one class to another class is called inheritance. Properties: Variables Behaviors: Methods The main purpose of the inheritance...
D

Deleted U.

1 0
0

Lambda Expressions in Java
A lambda expression, introduced in Java 8 is similar to a block of code resembling an anonymous function that can be passed to constructors or methods for execution as an argument. Examples: a)() ->...

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