There are four ways to create objects in java.Strictly speaking there is only one way(by using new keyword),and the rest internally use new keyword.
- Using new keyword: It is the most common and general way to create object in java. Example:
- Using Class.forName(String className) method: There is a pre-defined class in java.lang package with name Class. The forName(String className) method returns the Class object associated with the class with the given string name.We have to give the fully qualified name for a class. On calling new Instance() method on this Class object returns new instance of the class with the given string name.
- Using clone() method: clone() method is present in Object class. It creates and returns a copy of the object.
- Deserialization: De-serialization is technique of reading an object from the saved state in a file. Refer Serialization/De-Serialization in java