In this example, we will see a sample program to copying the contents of one text file to another in Java.
Java provides reflection API to do introspection of an object and modify its behavior on the run time. The class Class in the Java API forms the basis to identify the object class and its internal structure of that particular Class. The below three functions are important to get the class behavior. In this articles we will see, how to invoke a method dynamically at runtime.
The covariant return type allows narrowing down return type of the overridden method. This feature will help to avoid down casting on the client side. It allows programmer to program without the need of type checking and down casting. The covariant return type always works only for non-primitive return types.
If-else statement in java is used for conditional checks for decision making. You can have multiple hierarchies of if-else statements. Once any of the if or else-if condition satisfies it executes the block of statements corresponding to it
Switch case is another alternative for if-else statements. Switch case statement compares value in the object in the expression with the expressions associated with each case. A switch works only with primitive types like byte, short, char, and int and enumerated data types
This example shows how to remove duplicate from ArrayList using Comparator. The easiest way to remove duplicate is by passing the List to an Set. We will use Comparator to remove duplicate elements. Once you have the Set you can again pass it back to ArrayList.
Java is a high level, English like, object-oriented programming language with tons of
APIS(application programming interface) for developing applications. Java is a platform independent language with support for performing complex computation, graphics, server and mobile application development. Java language syntax looks pretty much like C and C++, however there are some differences such as absence of pointers, allows writing object-oriented code. Learning Java is easy for a developer with basic C programming experience.
This example shows how to remove duplicate from ArrayList. The easiest way to remove duplicate is by passing the List to an Set. As set doesn't support duplicates it will omit the duplicate values. Once you have the Set you can again pass it back to ArrayList.