|
Post by celebi on Apr 25, 2011 15:01:13 GMT -5
If there are other Java Resources here, let us share our knowledge and challenge ourselves for some technical stuff.
|
|
|
Post by celebi on Apr 25, 2011 15:10:03 GMT -5
Can a regular inner class have static declarations (like main)? If yes, can you show with an example. If no, then why not?
Answer will be posted tomorrow.
|
|
|
Post by courtneywalsh on Apr 26, 2011 1:23:39 GMT -5
Can a regular inner class have static declarations (like main)? If yes, can you show with an example. If no, then why not? Answer will be posted tomorrow. The answer is No. I don't know why but I think I have seen some error while compiling . Will wait for the answer.
|
|
tara
Full Member
Posts: 178
|
Post by tara on Apr 26, 2011 7:30:06 GMT -5
I think we can have static declaration, don't know about main method but a static variable if we can make inner class itself as static. Honestly, I never had use this technique so far in any of my projects
|
|
|
Post by celebi on Apr 26, 2011 8:10:04 GMT -5
For a "regular" inner class (without being defined as "static"), we cannot have static declarations. It is because: An inner class is associated with an instance of its enclosing class.
Eg: MyOuter mo = new MyOuter(); MyOuter.myInner mi = mo.new MyInner();
Tara, Most of the things discussed in the interview are something that we have not used in actual projects. Esp., the ones in India are way too technical. In one interview, the interviewer asked me the package name for a class in java.security. I have always used an IDE for coding and the packages are autopopulated by IDEs - never felt the need to remember the whole path :-)
I am also planning on opening a thread of Data algorithms, as I have heard that interviewers focus on the algorithm and speed etc. (so, we need to brush up on our skills back from our BE days :-) )
|
|
|
Post by celebi on Apr 26, 2011 8:13:25 GMT -5
If you are looking to brush up for interview for Java6 - I would suggest getting SCJP6 Study Guide by Sierra and Bates.
Okie, we can randomly post questions and challenge one another. Or Pick a topic, prep ourselves on it and post questions or notes on what we prepped.
I am going by chapters in that Study guide. So, planning to cover "1. Declarations and Access Controls" by this week.
|
|
tara
Full Member
Posts: 178
|
Post by tara on Apr 26, 2011 8:47:54 GMT -5
Celebi, thansk for suggesting SCJP6 Study Guide by Sierra and Bates.
Is it available online
|
|
|
Post by celebi on Apr 26, 2011 8:51:37 GMT -5
Which method names follow the JavaBeans standard? (Choose all that apply.) A. addSize B. getCust C. deleteRep D. isColorado E. putDimensions
|
|
|
Post by celebi on Apr 26, 2011 8:55:49 GMT -5
Given:
4. class Announce { 5. public static void main(String[] args) { 6. for(int __x = 0; __x < 3; __x++) ; 7. int #lb = 7; 8. long [] x [5]; 9. Boolean []ba[]; 10. enum Traffic { RED, YELLOW, GREEN }; 11. } 12. }
What is the result? (Choose all that apply.) A. Compilation succeeds B. Compilation fails with an error on line 6 C. Compilation fails with an error on line 7 D. Compilation fails with an error on line 8 E. Compilation fails with an error on line 9 F. Compilation fails with an error on line 10
**If you pick a fails result, explain why it would fail.
|
|
|
Post by celebi on Apr 26, 2011 9:04:12 GMT -5
Celebi, thansk for suggesting SCJP6 Study Guide by Sierra and Bates. Is it available online SCJP5 is available in Kindle version in Amazon. I could not find a ebook version for Java6
|
|
|
Post by readytogo on Apr 26, 2011 10:05:49 GMT -5
Which method names follow the JavaBeans standard? (Choose all that apply.) A. addSize B. getCust C. deleteRep D. isColorado E. putDimensions Ans: A, B, C and E D does not follow java bean naming standard
|
|
tara
Full Member
Posts: 178
|
Post by tara on Apr 26, 2011 14:04:41 GMT -5
Which method names follow the JavaBeans standard? (Choose all that apply.) A. addSize B. getCust C. deleteRep D. isColorado E. putDimensions A JavaBean basically holds properties which are exposed through getters/setters(mutator/accessor). A Javabean should not be constructed with larger degree of functionality(business logic) other than a place holder for properties and a simple getters and setters. If you have a String or int propery defined, then a get<Propert-name> is the standard naming convention For boolean type is<property-name> is the right one. So B and D are correct. A, B and E are incorrect since the method names starts with add/delete/put indiacting as if they are implementing additional business function which contradicts the purpose of a bean.
|
|
|
Post by celebi on Apr 27, 2011 8:45:31 GMT -5
Yes tara, B & D are correct.
Which method names follow the JavaBeans standard? (Choose all that apply.) A. addSize B. getCust C. deleteRep D. isColorado E. putDimensions Answer: B and D use the valid prefixes 'get' and 'is'. A is incorrect because 'add' can be used only with Listener methods. C and E are incorrect because 'delete' and 'put' are not standard JavaBeans name prefixes.
In addition to Javabean standards, there is also Javabean Listener Naming rules as given below: JavaBean Listener Naming Rules ■ Listener method names used to "register" a listener with an event source must use the prefix add, followed by the listener type. For example, addActionListener() is a valid name for a method that an event source will have to allow others to register for Action events. ■ Listener method names used to remove ("unregister") a listener must use the prefix remove, followed by the listener type (using the same rules as the registration add method). ■ The type of listener to be added or removed must be passed as the argument to the method. ■ Listener method names must end with the word "Listener".
Examples of valid JavaBean method signatures are public void setMyValue(int v) public int getMyValue() public boolean isMyStatus() public void addMyListener(MyListener m) public void removeMyListener(MyListener m)
Examples of invalid JavaBean method signatures are void setCustomerName(String s) // must be public public void modifyMyValue(int v) // can't use 'modify' public void addXListener(MyListener m) // listener type mismatch
|
|
|
Post by celebi on Apr 27, 2011 8:47:07 GMT -5
Given: 4. class Announce { 5. public static void main(String[] args) { 6. for(int __x = 0; __x < 3; __x++) ; 7. int #lb = 7; 8. long [] x [5]; 9. Boolean []ba[]; 10. enum Traffic { RED, YELLOW, GREEN }; 11. } 12. } What is the result? (Choose all that apply.) A. Compilation succeeds B. Compilation fails with an error on line 6 C. Compilation fails with an error on line 7 D. Compilation fails with an error on line 8 E. Compilation fails with an error on line 9 F. Compilation fails with an error on line 10
Answer: C, D, and F are correct. Variable names cannot begin with a #, an array declaration can’t include a size without an instantiation, and enums can’t be declared within a method. A, B, and E are incorrect based on the above information.
|
|
|
Post by celebi on Apr 27, 2011 14:35:55 GMT -5
QUESTION Given two files: 1. package pkgA; 2. public class Foo { 3. int a = 5; 4. protected int b = 6; 5. public int c = 7; 6. } 3. package pkgB; 4. import pkgA.*; 5. public class Baz { 6. public static void main(String[] args) { 7. Foo f = new Foo(); 8. System.out.print(" " + f.a); 9. System.out.print(" " + f.b); 10. System.out.println(" " + f.c); 11. } 12. }
What is the result? (Choose all that apply.) A. 5 6 7 B. 5 followed by an exception C. Compilation fails with an error on line 7 D. Compilation fails with an error on line 8 E. Compilation fails with an error on line 9 F. Compilation fails with an error on line 10
|
|