class A { } class B extends A { } public class Main { public static void main(String[] args) { A a = new A(); //A a = null; //Also check //A.class.isAssignableFrom(cls); B b = new B(); A ab = new B(); if (a instanceof A) { System.out.println("a instanceof A - true"); } else { System.out.println("a instanceof A - false"); } if (a instanceof B) { System.out.println("a instanceof B - true"); } else { System.out.println("a instanceof B - false"); } if (b instanceof A) { System.out.println("b instanceof A - true"); } else { System.out.println("b instanceof A - false"); } if (b instanceof B) { System.out.println("b instanceof B - true"); } else { System.out.println("b instanceof B - false"); } if (ab instanceof A) { System.out.println("ab instanceof A - true"); } else { System.out.println("ab instanceof A - false"); } if (ab instanceof B) { System.out.println("ab instanceof B - true"); } else { System.out.println("ab instanceof B - false"); } } } Result: a instanceof A - true a instanceof B - false b instanceof A - true b instanceof B - true ab instanceof A - true ab instanceof B - true
Sunday, February 19, 2012
Java Nuggets
Saturday, February 11, 2012
Motivation
Three rules John Wooden believed in:
- Never be late. Start on time, end on time.
- Not one word of profanity.
- Never criticize a teammate.
Other take away:
- Never try to better someone else.
- Always try to learn from others.
- Never cease to be best you could be.
- Never let what you cannot do...interfere with what you can do.
- Do not try to control that is not under your control, or you would lose control of things that you have control of.
- Do the best you are capable of. Things will work out as they should, as long as we do what we should.
- The journey is better than end.
- Have patience, Have faith.
- Reputation is what you perceive to be, Character is what you are.
Sunday, January 29, 2012
Motivation
Daniel Ek, CEO, Spotify
http://gigaom.com/2012/01/28/corbett-15-things-ceos-want-you-to-know/
Figure out what the top five most important stuff is, focus relentlessly on that and keep iterating. Less is more.
Dennis Crowley, CEO, FourSquare
Don’t let people tell you your ideas won’t work. If you have a hunch that something will work, go build it. Ignore the haters.
Sarah Prevette, Founder, Sprouter
Just do it. Get it out there, absorb the feedback, adjust accordingly, hustle like hell, persevere and never lose your swagger.
Sarah Lacy, CEO, PandoDaily
Follow your gut. it may be wrong, but you won’t regret it if you fail. You’ll regret it if you ignore your gut and fail.
Craig Newmark, Founder, Craigslist
Treat people like you want to be treated. Apply to customer service.
Gary Vaynerchuk, CEO, VaynerMedia
Do work for your customers, not for press or VCs. The end user is what matters long term.
Matt Mullenweg, CEO, Automattic
Only reinvent the wheels you need to get rolling.
Jason Goldberg, CEO, Fab.com
Pick one thing and do that one thing — and only that one thing — better than anyone else ever could.
Alexis Ohanian, CEO, Reddit
Make something people want. Then give more damns than anyone else about it and you’ll make something they love.
Chris Brogan, President, Human Business Works
Buy @ericries’s book. Beyond that? Build a platform. This is the big year.
Matt Howard, CEO, ZoomSafer
Startup wisdom: The number one job of a CEO is to not run out of money.
Brian Wong, CEO, Kiip
Always be learning from others. Whenever you meet someone, you don’t want something from them, you want to learn from them.
Seth Priebatsch, Chief Ninja, SCVNGR and LevelUp
Something my dad taught me: Ask forgiveness, not permission!
Hooman Radfar, Founder, Clearspring
Give away the wins, own the loses. Your job is to curate greatness.
Alexa Hirschfeld, CEO, Paperless Post
Reference:Users and employees are key predictive indicators of a company’s success; press and investors generally months behind.
http://gigaom.com/2012/01/28/corbett-15-things-ceos-want-you-to-know/
Sunday, January 8, 2012
Sunday, January 1, 2012
Good Java Tutorial Websites
http://www.javaworld.com/community/?q=javaqa
http://www.xyzws.com/javafaq/page/1
http://javarevisited.blogspot.com/2011/07/java-multi-threading-interview.html
http://docs.oracle.com/javase/tutorial/
http://intern-s-diary.blogspot.com/search?updated-max=2010-07-07T21%3A10%3A00-07%3A00&max-results=7
http://kalanir.blogspot.com/2011/04/nullsoft-scriptable-install-system-nsis.html
http://www.xyzws.com/javafaq/page/1
http://javarevisited.blogspot.com/2011/07/java-multi-threading-interview.html
http://docs.oracle.com/javase/tutorial/
http://intern-s-diary.blogspot.com/search?updated-max=2010-07-07T21%3A10%3A00-07%3A00&max-results=7
http://kalanir.blogspot.com/2011/04/nullsoft-scriptable-install-system-nsis.html
SCJP
package test; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.List; // Annotation @MyAnnotationType(version = 1.1, clients = { "Programs" }) class Main { public void method1() { } } public class Main1 extends Main { public static void main(String[] args) { Main1 m = new Main1(); m.method1(); } // Annotation provided by java // annotation tells the compiler to suppress specific warnings that it would otherwise generate. @SuppressWarnings({ "unchecked", "deprecation" }) // annotation informs the compiler that the element is meant to override an element declared in a superclass. @Override // annotation indicates that the marked element is deprecated and should no longer be used. @Deprecated public void method1() { List l; } } // The filename should be named same as public class or interface // meta annotation - annotation to annotation @Documented @Inherited // public enum ElementType { // TYPE, // Class, interface, or enum (but not annotation) // FIELD, // Field (including enumerated values) // METHOD, // Method (does not include constructors) // PARAMETER, // Method parameter // CONSTRUCTOR, // Constructor // LOCAL_VARIABLE, // Local variable or catch clause // ANNOTATION_TYPE, // Annotation Types (meta-annotations) // PACKAGE // Java package // } @Target({ ElementType.FIELD, ElementType.TYPE }) // public enum RetentionPolicy { // SOURCE, // Annotation is discarded by the compiler // CLASS, // Annotation is stored in the class file, but ignored by the VM // RUNTIME // Annotation is stored in the class file and read by the VM // } @Retention(RetentionPolicy.SOURCE) // simple annotation type @interface MyAnnotationType { public enum MyEnum { ONE, TWO, THREE }; //Annotation declaration should start with an 'at' sign like @, following with an interface keyword, following with the annotation name. //Method declarations should not have any parameters. //Method declarations should not have any throws clauses. //Return types of the method should be one of the following: primitives,String,Class,enum,array of the above types // string type String author() default "n/a"; // array type String[] clients() default { "Programs", "GUI", "TestJig" }; // enum MyEnum update() default MyEnum.ONE; // double type double version() default 1.0; }
http://docs.oracle.com/javase/tutorial/java/javaOO/annotations.html
http://www.developer.com/java/other/article.php/3556176/An-Introduction-to-Java-Annotations.htm
http://technicalmumbojumbo.wordpress.com/2008/01/13/java-custom-annotations/
http://www.ibm.com/developerworks/library/j-annotate2/index.html
Subscribe to:
Posts (Atom)