What is the difference between StringBuffer and String class ?

1 Answer

Answer :

Ans. A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. The String class represents character strings. All string literals in Java programs, such as "abc" are constant and implemented as instances of this class; their values cannot be changed after they are created.

Related questions

Description : How can I use the reverse method of the string buffer using Java?

Last Answer : Show your attempt at using reverse() yourself, and one of us might help you fix/improve it. No one is going to write your homework for you.

Description : Why is String immutable in Java ?

Last Answer : Ans. 1. String Pool When a string is created and if the string already exists in the pool, the reference of the existing string will be returned, instead of creating a new object. If ... opening files, etc. Making it mutable might possess threats due to interception by the other code segment.

Description : What is a String Pool ?

Last Answer : Ans. String pool (String intern pool) is a special storage area in Java heap. When a string is created and if the string already exists in the pool, the reference of the existing string will be returned, instead of creating a new object and returning its reference.

Description : String handling methods():

Last Answer : 1)int length(): it returns the number of characters in a given string . 7 2)char charAt(int where):it returns the character at the specified location. where must be a nonnegative ... of a string. String toUpperCase(): it converts all lowercase characters into uppercase character of a string.

Description : Difference between Abstract and Concrete Class ?

Last Answer : Ans. Abstract classes are only meant to be sub classed and not meant to be instantiated whereas concrete classes are meant to be instantiated.

Description : Difference between long.Class and Long.TYPE ?

Last Answer : Ans. They both represent the long primitive type. They are exactly the same.

Description : How to implement an immutable class ?

Last Answer : Ans. We can make a class immutable by 1. Making all methods and variables as private. 2. Setting variables within constructor. Public Class ImmutableClass{ private int member; ImmutableClass(int var){ member= ... (5); Now all members being private , you can't change the state of the object.

Description : What is an immutable class ?

Last Answer : Ans. Class using which only immutable (objects that cannot be changed after initialization) objects can be created.

Description : What is a Final Class ?

Last Answer : Ans. A Class that cannot be sub classed.

Description : How to display and set the Class path in Unix ?

Last Answer : Ans. To display the current CLASSPATH variable, use these commands in UNIX (Bourne shell): % echo $CLASSPATH To delete the current contents of the CLASSPATH variable, In UNIX: % unset CLASSPATH; ... To set the CLASSPATH variable, In UNIX: % CLASSPATH=/home/george/java/classes; export CLASSPATH

Description : Which access specifier can be used with Class ?

Last Answer : Ans. For top level class we can only use "public" and "default". We can use private with inner class.

Description : Can I import same package/class twice? Will the JVM load the package twice at runtime?

Last Answer : Ans. One can import the same package or same class multiple times. Neither compiler nor JVM complains wil complain about it. And the JVM will internally load the class only once no matter how many times you import the same class.

Description : What are the methods of Object Class ?

Last Answer : Ans. clone() - Creates and returns a copy of this object. equals() - Indicates whether some other object is "equal to" this one. finalize() - Called by the garbage collector on an object ... ), and wait() - Play a part in synchronizing the activities of independently running threads in a program.

Description : Are constructors inherited? Can a subclass call the parent's class constructor? When?

Last Answer : Ans. You cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of one of it's superclasses. One of the main reasons is because ... developer the ability to override a superclasses constructor you would erode the encapsulation abilities of the language.

Description : Can a lock be acquired on a class ?

Last Answer : Ans. Yes, a lock can be acquired on a class. This lock is acquired on the class's Class object.

Description : Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?

Last Answer : Ans. java.lang.StringBuffer.

Description : Difference between object instantiation and construction ?

Last Answer : Ans. Though It's often confused with each other, Object Creation ( Instantiation ) and Initialization ( Construction ) are different things in Java. Construction follows object creation. Object ... provides one default implementation to set the default values according to the member data types.

Description : Difference between Vector and ArrayList ?

Last Answer : Ans. Vectors are synchronized whereas Array lists are not.

Description : Difference between Overloading and Overriding ?

Last Answer : Ans. Overloading - Similar Signature but different definition , like function overloading. Overriding - Overriding the Definition of base class in the derived class

Description : What is difference between Encapsulation And Abstraction?

Last Answer : Ans. 1.Abstraction solves the problem at design level while encapsulation solves the problem at implementation level 2.Abstraction is used for hiding the unwanted data and giving relevant data. ... and Display Screen are connect with each other using different circuits , it explains Encapsulation.

Description : what is the use of cookie and session ? and What is the difference between them ?

Last Answer : Ans. Cookie and Session are used to store the user information. Cookie stores user information on client side and Session does it on server side. Primarily, Cookies and Session are used for ... for storing the textual information. Session can be used to store both textual information and objects.

Description : What is the difference between time slicing and preemptive scheduling ?

Last Answer : Ans. In preemptive scheduling, highest priority task continues execution till it enters a not running state or a higher priority task comes into existence. In time slicing, the task continues its execution for a predefined period of time and reenters the pool of ready tasks.

Description : What is the difference between yield() and sleep()?

Last Answer : Ans. When a object invokes yield() it returns to ready state. But when an object invokes sleep() method enters to not ready state.

Description : What are the difference between Threads and Processes ?

Last Answer : Ans. 1. when an OS wants to start running program it creates new process means a process is a program that is currently executing and every process has at least one thread ... was considered that thread makes the runtime environment asynchronous and allow different task to perform concurrently.

Description : Difference between HashMap and Hashtable?

Last Answer : Ans. Hashtable is synchronized whereas HashMap is not. HashMap allows null values whereas Hashtable doesn’t allow null values.

Description : Difference between Checked and Unchecked exceptions ?

Last Answer : Ans. Checked exceptions and the exceptions for which compiler throws an errors if they are not checked whereas unchecked exceptions and caught during run time only and hence can't be checked.

Description : Difference between == and .equals() ?

Last Answer : Ans. "equals" is the member of object class which returns true if the content of objects are same whereas "==" evaluate to see if the object handlers on the left and right are pointing to the same object in memory.

Description : Difference between Public, Private, Default and Protected ?

Last Answer : Ans. Private - Not accessible outside object scope. Public - Accessible from anywhere. Default - Accessible from anywhere within same package. Protected - Accessible from object and the sub class objects.

Description : What is the difference between List, Set and Map ?

Last Answer : Ans. List - Members are stored in sequence in memory and can be accessed through index. Set - There is no relevance of sequence and index. Sets doesn't contain duplicates whereas multiset can have duplicates. Map - Contains Key , Value pairs.

Description : Difference between TreeMap and HashMap ?

Last Answer : Ans. They are different the way they are stored in memory. TreeMap stores the Keys in order whereas HashMap stores the key value pairs randomly

Description : What to you think of taking an eight week online Java cerfitcate from Robertson College?

Last Answer : Eight week online Java cerfitcate from Robertson College not offered this year. Please just find me a good free online Java YouTube videos that worked for you? Also how do I purchase a Java and all its parts ... ? I just bought a Chromebook last month and will have to save money to buy a new laptop.

Description : How do you say "java" in Spanish?

Last Answer : answer:Cafe. Or, you can pronounce it haba.

Description : How do I install Leximancer?

Last Answer : Double click it, jar files just run. You may have to start it through the command prompt.

Description : What is your go-to cup of coffee - and what is your preferred brew?

Last Answer : answer::) That’d be a one-shot soya latte, in a medium sized cup, from Costa… If I have to go to a Starbucks, it’s the same drink but in a large sized cup – their coffee is stronger. Note – soya milk in the UK is nowhere near as sweet as soy milk in the US. It’s more nutty in flavour.

Description : Why abstraction in java is called as a mathematical entity?

Last Answer : answer:Abstract data classes are analogous to mathematical constructions. In Euclidean geometry, for example, the axioms would be like the methods in an abstract Java class. Since the terms in the axioms ... allow you to work with types that really are undefined and that have to be instantiated.

Description : How can I easily save a java game for offline use?

Last Answer : Can you maybe try this?

Description : How do I autofill an adobe flash login popup?

Last Answer : answer:Set up your Firefox options- Make sure remember search & form history : is checked under Firefox Privacy settings. You could choose remember passwords from sites under Security if you want. And ... I start typing. All of the above might work better than roboform and work in Flash too.

Description : Java Embedded Database for Global File System?

Last Answer : answer:Perhaps something like SQLite? I believe if shared on a GFS the application will lock the database during writing. And of course SQLite an embedded database, and can be used by Java as well as C++.

Description : A coffee lover's question - or rather, the debunking of a java myth. Proceed with caution.

Last Answer : Thankfully,no.I am a potter and throw stoneware mugs to sell to people who feel exactly as you do.there are alot of you out there :))

Description : Why do Rails developers hate Java so much?

Last Answer : Hating any tool makes no sense. You can’t hate tools, you can hate users or abusers thereof. But even that is not useful. Every tool has its use, and it may be ‘superior’ for a particular solution than another. That’s all there is.

Description : Django in the enterprise?

Last Answer : I think Glassfish + JRuby + Rails is pretty common. Perhaps Glassfish + Jython + Django?

Description : How to format text (like bold, italic) in jabber/gtalk?

Last Answer : Not sure for jabber. But for Google Talk it's actually the same as for Fluther. Surround your text with the modifiers to style the string. Asterisks will make it bold, underscores will make it italicized, and dashes ... use it, but I don't know if a robot script will act the same. I hope that helps.

Description : Why can't I get java to download?

Last Answer : Look at the help files. that is a known error with a known workaround. You have to kill a process, or uninstall your previous iteration.

Description : Can an iPod touch run .jar games?

Last Answer : Nope, iPod touch doesn’t run Java, or Adobe :(

Description : Can I set a 'limit' on an integer value in a java applet?

Last Answer : At the beginning of the function, always check to see if ‘nowplaying’ is > 9. If it is, set it to 0 and then have the function run normally. I’m familiar with C++, so I can’t really help you with the syntax, but this should be pretty easy.

Description : How do I program a neural network from scratch using Java?

Last Answer : There are many implementations of neural networks... What will you be using it for? I wrote a fairly simple one in college in Java just using basic data types. Can you give me some more info?

Description : ajc gone blind?

Last Answer : answer:These folks are having the same problem. I don’t know much about this type of stuff, but they do. http://forum.springsource.org/archive/index.php/t-25945.html

Description : Can you play runescape on an iPhone?

Last Answer : Oh dear.

Description : Which Jabber server software has the smallest memory footprint?

Last Answer : answer:Andrew, I not sure what version of Wildfire (now called OpenFire) you are using?We are running Wildfire at my work on WinTel boxes and its memory footprint is small. I've also used ... this document that compares the various Jabber servers with an extensive list of features. Good Luck! R

Description : Can I get MobiTV or Java on my iPhone?

Last Answer : you can’t get Java because you can’t change the iPhone it’s self. But just try a Slingbox for mobile tv after the SDK.