Write a program to count the occurrences of an element in an array is one of the basic question which will be asked in an Java Interview. After the introduction of Collection framework performing this operation is a pretty easy task. Let see how we can count the occurrence using HashMap. [Read more…]
We will be requiring the below jars to be put in the classpath for performing the marshalling operation.
Type Casting in Java is nothing but converting a primitive or interface or class in Java into other type. There is a rule in Java Language that classes or interface which shares the same type hierrachy only can be typecasted. If there is no relationship between then Java will throw ClassCastException. Type casting are of two types they are
- Implicit Casting (Widening)
- Explicit Casting (Narrowing)
The command line argument is the argument which is passed at the time of running a Java application. Java can take any number of arguments from the command-line, You could see that there will be String args used in the declaration of the main() method, which tells us that Java can takes all the argument which is passed in the command-line as String, but the question here is that how to pass the command-line argument to Java. [Read more…]
What is an Object in Java ?
We all know that Java is an Object Oriented Programming Language, which entirely rely on Objects and Classes. Any entity which has State and Behavior is known as Object, for example note, pen, bike, book etc. It can be either physical or logical. All the objects should have the below two characteristics
- State : State represents the bof the objects, Lets take car as example car has name, color, engine etc.
- Behavior : Behavior represents the functionality of that object. With car you can drive, apply breaking, change gear etc.
A Constructor which has parameters in it called as Parameterized Constructors, this constructor is used to assign different values for the different objects. In the below example we have a constructor for the Car class which takes in the the value and sets to the property, lets try to set the value for the property “carColor” [Read more…]
Swapping of two numbers without the third or temporary variable is one of the most popular interview question asked, most of the freshers failed to solve without the third variable. Lets now take a look into the possible approaches. [Read more…]