Write a program to count the occurrences of an element in an array is one of the basic question which will be asked in a 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...]
How to Convert Java Object to JSON using JAXB
In this example we will see how we can convert a Java Object into an JSON using JAXB Marshalling Technique. JAXB Dependency We will be requiring the below jars to be put in the classpath for performing the marshalling operation. jaxb-api.jar org.eclipse.persistence.moxy-2.6.2.jar eclipselink-2.6.2.jar validation-api-1.1.0.Final.jar … [Read more...]
Type Casting in Java – Implicit and Explicit Casting
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) … [Read more...]
For Loop in Java with Example
For Loop in Java is one of the basic and most used looping statement. It executes a block of statements repeatedly until the condition specified becomes false. In this article we will learn end to end on how to use for loop in Java. … [Read more...]
Top 14 Java Interview Questions on Static keyword
1. What is static keyword in Java? Static is a Non-Access Modifier. Static can be applied to variable, method, nested class and initialization blocks (static block). 2. What is a static variable? A Static variable gets memory allocated only once during the time of class loading. All the instance of the class share the same copy of the variable, a static variable can … [Read more...]
Taking Command Line Arguments in Java
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 … [Read more...]
Object and Object Class in Java
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 … [Read more...]
Parameterized Constructor in Java with Example
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...]
Java Program to swap two numbers without using third variable
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. In this article, lets learn the possible ways to swap two numbers without using third variable … [Read more...]
Java ArrayList contains() Method Example
The contains() method of java.util.ArrayList class returns true if this list contains the specified element. … [Read more...]
Override toString() method of ArrayList in Java
When we are working with ArrayList of Objects then it is must that we have to override toString() method of Java ArrayList to get the output in the desired format. Lets learn how to override toString() method. … [Read more...]
Java Constructor.newInstance() method Example
In my previous article we have seen how to use Class.newInstance() method in creating object for class dynamically but there exist a problem the newInstance() method of Class class can invoke only no-arg constructor of the class when a class has parameterized constructors we cannot use newInstance() method of Class class at that place we need to go for the newInstance() method … [Read more...]
- 1
- 2
- 3
- …
- 6
- Next Page »