confusion with Java programming -


i have started learning core java , 1 particular thing driving me crazy. know how create object

something

mouse mouse = new mouse (); 

however don't understand whether these objects too:

connection conn = drivermanager.getconnection(url, user, password); statement st = conn.createstatement(); resultset rs1 = st.executequery(""); 

if not - they? appreciate if can clear confusion.

yes, conn, st, , rs1 in samples objects, mouse. creating mouse constructor, so:

mouse mouse = new mouse() 

but add static method mouse create new instance of mouse, drivermanager.getconnection(url, user, password); returns new instance of statement. example:

public class mouse {      public mouse() { }      public static mouse createnewmouse() {          return new mouse();     }   } 

then instead of using constructor

mouse mouse = mouse.createnewmouse(); 

in case of mouse class, there no reason use static method that. of comments have mentioned, however, there called factory method design pattern can hide of complexity of instantiating complex objects.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -