Do declared properties require a corresponding instance variable?

If you are using the Modern Objective-C Runtime (that’s either iOS 3.x or greater, or 64-bit Snow Leopard or greater) then you do not need to define ivars for your properties in cases like this. When you @synthesize the property, the ivar will in effect be synthesized also for you. This gets around the “fragile-ivar” … Read more

Instance variable: self vs @

Writing @age directly accesses the instance variable @age. Writing self.age tells the object to send itself the message age, which will usually return the instance variable @age — but could do any number of other things depending on how the age method is implemented in a given subclass. For example, you might have a MiddleAgedSocialite … Read more

Ruby class instance variable vs. class variable

Instance variable on a class: class Parent @things = [] def self.things @things end def things self.class.things end end class Child < Parent @things = [] end Parent.things << :car Child.things << :doll mom = Parent.new dad = Parent.new p Parent.things #=> [:car] p Child.things #=> [:doll] p mom.things #=> [:car] p dad.things #=> [:car] … Read more

Should I instantiate instance variables on declaration or in the constructor?

There is no difference – the instance variable initialization is actually put in the constructor(s) by the compiler. The first variant is more readable. You can’t have exception handling with the first variant. There is additionally the initialization block, which is as well put in the constructor(s) by the compiler: { a = new A(); … Read more

How do servlets work? Instantiation, sessions, shared variables and multithreading

ServletContext When the servlet container (like Apache Tomcat) starts up, it will deploy and load all its web applications. When a web application is loaded, the servlet container creates the ServletContext once and keeps it in the server’s memory. The web app’s web.xml and all of included web-fragment.xml files is parsed, and each <servlet>, <filter> … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)