Thus, they are similar to class except that they lack instance variables, and their methods are declared without anybody. An array is a group of like-type variables referred by a common name, having continuous memory. Primitive value objects are stored in an array.
It provides code optimization since we can sort data efficiently and also access it randomly. The only flaw is that we can have a fixed-size element in an array. The String class, which implements the CharSequence interface, defines several methods for string manipulation tasks. The list of most commonly used string methods are mentioned below:. Multitasking: Process of executing multiple tasks simultaneously to utilize the CPU. A thread is always in one of the following five states; it can move from one state to another in a variety of ways, as shown.
The run method is declared in the Runnable interface is required for implementing threads in our programs. The exception is an abnormality or error condition caused by a run-time error in the program; if this exception object thrown by the error condition is not caught and handled properly, the interpreter will display an error message. If we want to avoid this and want the program to continue, we should try to catch the exceptions.
This task is known as exception handling. A code can have more than one catch statement in the catch block; when an exception in the try block is generated, multiple catch statements are treated like cases in a switch statement. Finally, statement: used to handle exceptions that are not caught by any previous catch statements. A final block is guaranteed to execute, regardless of whether or not an exception is thrown.
Collection of related records stored in a particular area on the disk termed as the file. The files store and manage data by the concept of file handling. Java uses the concept of streams to represent an ordered sequence of data, a path along which data flows. Thus, it has a source and a destination.
They are used to read 8-bit bytes include a superclass known as InputStream. InputStream is an abstract class and defines the methods for input functions such as :. These classes are derived from the base class OutputStream. OutputStream is an abstract class and defines the methods for output functions such as :. The collections framework is contained in java. The classes available in the collection framework implement the collection interface and sub-interfaces. They also implement Map and Iterator interfaces.
Created in , object-oriented programming, Java, was developed to overcome the flaws of modular programming. Java introduced concepts like Abstraction, Encapsulation for robust and secure code.
Similarly, the concept of Polymorphism, Inheritance, and Classes removed redundancy in the code. Java is used in various sectors like internet security, Android Development, Web Development, and more. You can use both Constructor-based and Setter-based Dependency Injection. The best solution is to use constructor arguments for mandatory dependencies and setters for optional dependencies. Spring beans scope interview questions - The Spring Beans are Java Objects that form the backbone of a Spring application.
They are instantiated, assembled, and managed by the Spring IoC container. These beans are created with the configuration metadata that is supplied to the container, for example, in the form of XML definitions. Beans defined in the spring framework are singleton beans. By default, it is set to true. So, all the beans in the spring framework are by default singleton beans. A Spring Bean definition contains all configuration metadata that is needed for the container to know how to create a bean, its lifecycle details, and its dependencies.
When defining an in Spring, we can also declare a scope for the bean. It can be defined through the scope attribute in the bean definition. On the other hand, when the same instance of a bean must be returned by Spring every time it is needed, the bean scope attribute must be set to a singleton.
When a bean is only used as a property of another bean it can be declared as an inner bean. Inner beans are always anonymous and they are always scoped as prototypes. Wiring, or else bean wiring is the case when beans are combined together within the Spring container. When wiring beans, the Spring container needs to know what beans are needed and how the container should use dependency injection to tie them together.
The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators other beans for a bean by inspecting the contents of the BeanFactorywithout using and elements.
The autowiring functionality has five modes that can be used to instruct Spring container to use autowiring for dependency injection:. The java-based configuration option enables you to write most of your Spring configuration without XML but with the help of few Java-based annotations. An example is a Configuration annotation, which indicates that the class can be used by the Spring IoC container as a source of bean definitions. Another example is [email protected] annotated method that will return an object that should be registered as a bean in the Spring application context.
An alternative to XML setups is provided by an annotation-based configuration that relies on the bytecode metadata for wiring up components instead of angle-bracket declarations. Instead of using XML to describe a bean wiring, the developer moves the configuration into the component class itself by using annotations on the relevant class, method, or field declaration. Annotation wiring is not turned on in the Spring container by default.
In order to use annotation-based wiring, we must enable it in our Spring configuration file by configuring the element. This annotation simply indicates that the affected bean property must be populated at configuration time, through an explicit property value in a bean definition, or through auto wiring. The container throws BeanInitializationException if the affected bean property has not been populated.
The Autowired annotation provides more fine-grained control over where and how auto wiring should be accomplished. When there are more than one beans of the same type and only one is needed to be wired with a property, [email protected] annotation is used along with Autowired annotation to remove the confusion by specifying which exact bean will be wired. When using the Spring JDBC framework the burden of resource management and error handling is reduced.
So developers only need to write the statements and queries to get the data to and from the database. Consider the following example. The hashCode method returns the same integer number if two keys by calling equals method are identical. If two objects do not produce an equal result by using the equals method, then the hashcode method will provide the different integer result for both the objects.
The equals method is used to check whether two objects are the same or not. It needs to be overridden if we want to check the objects based on the property. For example, Employee is a class that has 3 data members: id, name, and salary. However, we want to check the equality of employee object by the salary.
Then, we need to override the equals method. Two different keys with the same hash value are known as hash-collision. Two separate entries will be kept in a single hash bucket to avoid the collision. There are two ways to avoid hash-collision. The default size of load factor is 0.
So, 12 is the default capacity of Map. The Iterator in java which immediately throws ConcurrentmodificationException, if any structural modification occurs in, is called as a Fail-fast iterator. Fail-fats iterator does not require any extra space in memory. The length of an array can be obtained using the property of length whereas ArrayList does not support length property, but we can use size method to get the number of objects in the list.
Consider the following syntax:. Consider the following syntax to convert the ArrayList to the List object. We can obtain java ArrayList Read-only by calling the Collections. To reverse an ArrayList, we can use reverse method of Collections class. To sort the ArrayList in descending order, we can use the reverseOrder method of Collections class. LinkedLists are better to use for the update operations whereas ArrayLists are better to use for the search operations. JavaTpoint offers too many high quality services.
Mail us on [email protected] , to get more information about given services. Please mail your requirement at [email protected] Duration: 1 week to 2 week. All Interview. HashSet implements set interface. So, HashSet does not allow duplicates. However, HashSet does not support ordering. The order in which elements are inserted is not maintained.
Sachin is Duplicate. So will not be added. LinkedHashSet implements set interface and exposes similar operations to a HashSet.
Difference is that LinkedHashSet maintains insertion order. When we iterate a LinkedHashSet, we would get the elements back in the order in which they were inserted.
TreeSet implements this interface. Let's look at an example with TreeSet. Note that elements in TreeSet are sorted. Lower method finds the highest element lower than specified element. Floor method finds the highest element lower than or equal to specified element. Corresponding methods for finding lowest number higher than specified element are higher and ceiling. HashMap and TreeMap. HashMap implements Map interface — there by supporting key value pairs.
TreeMap is similar to HashMap except that it stores keys in sorted order. We will now insert a Cricketer with key dravid. In sorted order,dravid comes before sachin. So, the value with key dravid is inserted at the start of the Map.
We will now insert a Cricketer with key ponting. In sorted order, ponting fits in between dravid and sachin. TreeMap is a good example of a NavigableMap interface implementation. Note that keys in TreeMap are sorted. Corresponding methods for finding lowest key higher than specified key are higher and ceiling. A few examples using the Map created earlier below. Synchronized collections are implemented using synchronized methods and synchronized blocks.
Only one thread can executing any of the synchronized code at a given point in time. This places severe restrictions on the concurrency of threads — thereby affecting performance of the application. Post Java 5, collections using new approaches to synchronization are available in Java.
These are called concurrent collections. More details below. Examples of new approaches are :. We would discuss each of these approaches in detail below. Copy on Write collections are typically used in Subject — Observer scenarios, where the observers very rarely change.
0コメント