Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
    Bookmark Topic Watch Topic
  • New Topic

difference between instantion and object  RSS feed

 
ramchander yshetti
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Report post to moderator
please tell me about the difference between inistation and object.

i.e Class.forName(........)
gives the instantion of class, how it different from object
 
tapan hoskeri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Report post to moderator
Creating an object effectively means 'instantiating an object of a said class', so the terms are interchangeable. The Class.forName() method is an alternative to calling 'new' as far as object creation goes.

For eg, both the following lines of code do pretty much the same thing...that is to create an object of the class String

try
{
String a = (String)Class.forName("java.lang.String").newInstance();
//Creates an object of class String
}
catch (InstantiationException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}


String b = new String(); //also creates an object of class String
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!