Thursday, May 12, 2011

Java Quiz


True/False questions:

a) You cannot define a method with the same name as the class name and with a return type.
Ans. False.

b) One advantage of static factory method is that like constructors, they are required to create a new object each time they are invoked?
Ans. False. One advantage of static factory method is that unlike constructors, they are not required to create a new object each time they`re invoked

c) Clone method of object class does a shallow copy of this object.
Ans. True

d) Java supports multiple inheritances.
Ans.  No

e) A method that is overridden in the subclass must have the same return type and parameter list.
Ans.  True

f) When a derived class is instantiated, its base class no-argument constructor is called whether or not an explicit call to super( ) is made.
Ans. True

g) Defining formal parameters requires including each parameters type.
 Ans: True. In order for the compiler to check to see if a method call is correct, the compiler  needs to know the types for the parameters being passed. Therefore, all formal parameters (those defined in the method header) must include their type. This is one element that makes Java a Strongly Typed language.

h) While multiple objects of the same class can exist, there is only one version of the class.
Ans: True. Explanation: A class is an abstraction, that is, it exists as a definition, but not as a physical instance. Physical instances are created when an object is instantiated using new. Therefore, there can be many
objects of type String, but only one String class.

Multiple choice questions:

a) In a *.java file you can define classes with the following access modifier(s):

1-  Public classes are only allowed.
2-  Public, private, protected and package level access classes.
3-  Public and package level access classes.
4-  Only one public class in a *.java file is allowed.
5-  One public class and package level access classes.

Ans. 2&3

b) You can add methods to this type. With an implementation, and it will still satisfy the open closed principle.

1-Abstract class
2-Interface
3-Inner class
4-Final class

Ans. 1

c) When will we have static method?

1. When a method doesn't need to access an object state.
2. When a method only needs access to class fields.
3. When it is a factory method.
4. When the method will only be public.
5. None of the above

Ans. 1

d) Consider the following code:
class NewString extends java.lang.String

1. Results in error because java.lang.String is final
2. Results in error because class body is not defined
3. Results in error because the class is not declared public
4. Results in error because String is abstract
5. Compiles successfully

Ans. 1

e) Which one of these primitive types are unsigned?

1. int
2. float
3. char
4. double
5. long

Ans.  3

f) A subclass can directly access

1. public members of a superclass   
2. private members of a superclass   
3. all members of a superclass   
4. none of the members of a superclass 

Ans. 1

g) What is byte code in the context of Java?

1. The type of code generated by a Java compiler
2. The type of code generated by a Java Virtual Machine
3. It is another name for a Java source file
4. It is the code written within the instance methods of a class.
5. It is another name for comments written within a program.

Ans. 2

h) submarine.dive(depth);
What can you say for sure?

1. depth must be an int
2. dive must be a method
3. dive must be the name of an instance field.
4. submarine must be the name of a class
5. submarine must be a method.

Ans. 2

Tuesday, September 21, 2010

Nice quote..

“And, when you want something, all the universe conspires in helping you to achieve it.” The Alchemist by Paulo Coelho

Monday, August 30, 2010

Using multiple Siebel Repositories in local database

If you have multiple repositories in your server database and would like to have a few of them in your local database too then read on.

Scenario: Your Server database has 3 repositories. 1) Siebel Repository 2) Siebel Repository A 3) Siebel Repository B. You already have a local database (.dbf) file extracted with Siebel Repository. You would like to check out and check in from Siebel Repository A.

Login to Tools. Tools -> Check Out... One pop up window opens. The top line has Siebel Repository. In this dropdown you can see all other Siebel repositories. Do a get of Siebel Repository A. Now you will have Siebel Repository and Siebel Repository A in your local database. Login to Tools. Select File-> Open Repository.


Now, select the repository of your choice which in this case is - Siebel Repository A. After selecting this repository you can do a check in and check out of any objects from this repository.

Friday, June 11, 2010

Ever faced Siebel crashes??

I thought to share my experience of Siebel Crashes and also would like to know if you faced one and the corresponding fixes.

This behaviour came up while using scripting with Siebel. We had made a business service (BS) which was called from button clicks both from browser side and server side. When we called the BS from browser side went out of context, called it from server side went out of context and then again called from browser side.. boom .. Siebel crashed. Probably blame it on the Siebel architechture. There are two ways we tried to fix it. First approach was to make the design change and call the BS only once. Second approach was also design change and to do away with the browser scripts and we moved all the code to the server side and it worked fine.

Wednesday, June 9, 2010

Dynamic Labels/Controls in Siebel Form Applet

I got a requirement from business to make around 10 form applets and also give them access from some admin screen to make new applets on run-time. The applets are more of question and answers. So, we came up with dynamic labels/control on Siebel Form Applets.  Below is how it's done.

Create a new control (DynamicLabel) in the form applet with HTML type as PlainText.


This control is mapped to a field (Field A) on the BC. 

As there were 15 different applets in this case, so we had a field with 10 diffrent values which we had finalised and 5 more free values. (These values were from a picklist and let's call it Field B for now.)

Now, we made a calculated field Field A and based on the value of Field B we made caption A, caption B and so on (till 15 new captions) to a last value which was blank.

So to say, if Field B value was "Action" we would display "My Action" in the Field A and if Field B value was "Event" then we displayed "My Event" in Field A. If there were no matching values then as calculated field had a null value therefore, this label did not display on the Form Applet.

As for the Control, we used browser script to display or Hide the control based on the value of Field B. This control can be of Text or TextArea. Siebel has a limitation that browser script can only hide dynamically controls of type CheckBox, ComboBox, TextBox, TextArea, Label.

Using HTML type as Plain Text for the caption has the advantage that it is no longer dependent on the browser script to hide the control and in real time when the value is null then it does not display at all and feels like as if nothing is present at that location in the form applet.