1Briefly explain the difference between an instance method a
1.Briefly explain the difference between an instance method and a static method.
2. Why should you avoid excessive String concatenation using the + operator?
3. Why is an ArrayList (or any collection class) better than an array?
4. A class or object is a better representation of data than parallel arrays. Why?
Solution
1)
If u declare one method as a static then we can call that method using class name, that method is independent of that object.You declare them using the CLASS-DATA statement.
If u declare one method as a instance then we can call that method using object name, that method is dependent of that object.You declare them using the DATA statement.
2)
String is one of the powerful classes that resides in the java.lang package. This is an immutable class and any operation that causes a change in the original string results in creating a new object. So when we do the operation that results in the alteration of any string this creates a performance bottleneck
These are the ways by which two or more strings can be concatenated.
1) Using the [+] plus operator.
2) Using the concat method of String Class.
3) Using the append method of StringBuilder Class.
3)
Work on a large codebase and a previous group of developers used arrays everywhere. It made the code very inflexible. After changing large chunks of it to Lists we noticed no difference in speed
Array and arraylist in java is considered as a starting interview question . This question checks whether candidate know about static and dynamic nature of array. We have already discussed other popular java interview questions like difference between comparable and comparator and difference between arraylist and vector . Difference between array and arraylist in java include eight points namely Resizable, Performance, Traversal ,Primitives , Length , Type-Safety, Adding elements , Multi-dimensional
4)
In the parallel arrays approach, each record is broken down into its component fields, and arrays are assembled for each field across the collection. For example, consider a store keeping track of purchases, where for each purchase the name of the item, price, and day of the week the purchase was made are recorded. The data would be stored in 3 arrays, one each for names, prices, and days. All arrays would be of the same length, equal to the total number of purchases. (For another example, including Java code, see the DIC tutorial
