Monday, April 21, 2008




Posted by Picasa

Tuesday, January 30, 2007

Important Points in SCJP Preparation

Important Points in SCJP Preparation
Some important tipsConstructors:1. If the sub class constructor doesn’t call any super class or its other constructor explicitlya. If the super class has default constructor(explicitly or implicitly and visible), theni. super() is invoked implicitly if no exception is thrown or the sub class constructor throws that exceptionii. Compiler error otherwise.b. Compiler error otherwise.2. If the sub class constructor call super class constructor explicitly(using super keyword)a. If the super class has such a constructor and visible, then it is calledb. Compiler error otherwise.3. If the sub class constructor call its other constructor explicitly(using this keyword)a. If the sub class has such a constructor, then it is calledb. Compiler error otherwise.4. The super or this constructor call can be only the first line of any constructor and only one of them can be used at a time. As to resolve the point, when to call the base class constructor and to call what base class constructor.Overriding:1. The static methods can’t be overridden at all.a. The static methods are resolved and invoked with reference type and not with the type of object the reference point to.2. The private methods are not overridden at all.a. The private method even with the same signature as base class method is a new method in the super class.3. The protected and public can be overriddena. But the visibility can’t be reducedb. Can throw only the same exception or any sub class of the exception that is thrown by the base class hidden methodc. These are resolved and invoked with the type of object the reference point to.

Overloading:1. The method name is the name2. The signature is differenta. The number of parametersb. The type of parameters3. These are resolved asa. Look for the functions with appropriate number of parametersb. Match for the type of each parameteri. If exact type of the parameter is not found,1. Then search for its super class types(due to multiple inheritance thru interface)a. If there are more than one found, then Compiler error as ambiguity2. Compiler error if none foundc. Compiler error if none found

http://www.javadeveloper.co.in/scjp/scjp-mock-exams.html.....mock exams


Declarations and Access Control

Modifiers fall into two categories:
* Access modifiers:public,protected,private
* Nonaccess modifiers (includingstrictfp,final, andabstract)
* A class can be declared with only public or default access. (Additionally Strictfp, abstract, final)
* The other two access control levels protected,private don’t make sense for a class
* Four access controls (which means all three modifiers + default) work for most method and variable declarations
Class Access (Visibility)
* Default Access: A class with default access can be seen only by classes within the same package.
* Note: If class A and class B are in different packages, and class A has a default access, class B won’t be able to create an instance of class A, or even declare a variable or a return type of class A.
* Do these two things to make it work, place class A, class B in the same package (or) declare class A with public access modifier.
* Exam Watch : When you see a question with complex logic, be sure to look at the access modifiers first. That way, if you spot an access violation (for example, a class n package A trying to access a default class in package B), you’ll know the code won’t compile so you don’t have to bother working through the logic. It’s not as if, you know, you don’t have anything better to do with your time while taking the exam. Just choose the “Compilation fails” answer and zoom on to the next question.
* Public Access: A class declaration with the public keyword gives all classes from all packages access to the public class. - visible to all classes in all packages.
Other (Nonaccess) Class Modifiers:
* Can modify a class declaration using the keyword final,abstract, or strictfp.
* These modifiers are in addition to whatever access control is on the class. You can’t always mix non abstract modifiers.
* never, ever, ever mark a class as both final and abstract. (Tell me why?)
* strictfp is a keyword and can be used to modify a class or a method, but never a variable.
* Marking a class as strictfp means that any method code in the class will conform to the IEEE754 standard rules for floating points.
* Final Classes When used in a class declaration, the final keyword means the class can’t be sub classed. No other class can ever extend (inherit from) a final class.
* Final can be used to modify a class or a method or a variable.
* Abstract Classes: An abstract class can never be instantiated. It is to be extended (subclassed).
* Abstract can be used to modify a class, a method but never a variable.
* Exam Watch: Look for questions with a method declaration that ends with a semicolon, rather than curly braces. If the method is in a class—as opposed to an interface—then both the method and the class must be marked abstract. You might get a question that asks how you could fix a code sample that includes a method ending in a semicolon, but without an abstract modifier on the class or method. In that case, you could either mark the method and class abstract, or remove the abstract modifier from the method. Oh, and if you change a method from abstract to non abstract, don’t forget to change the semicolon at the end of the method declaration into a curly brace pair!
* Remember: Even a single method is abstract, the whole class must be declared abstract.
* Can put non abstract methods in the abstract class.
* Exam Watch: You can’t mark a class as both abstract and final. They have nearly opposite meanings. An abstract class must be subclassed, whereas a final class must not be subclassed. If you see this combination of abstract and final modifiers, used for a class or method declaration, the code will not compile.
Method and Variable Declarations and Modifiers
* Methods and instance (nonlocal) variables are collectively known as members. Can modify a member with both access and non-access modifiers.
* Member Access: public, protected, private, default.
* Exam Watch: It’s crucial that you know access control inside and out for the exam. There will be quite a few questions with access control playing a role. Some questions test several concepts of access control at the same time, so not knowing one small part of access control could blow an entire question.
* Question: What does it mean for code in one class to have access to a member of another class? The member in class A should be visible to class B
* You need to understand two different access issues: 1. Whether method code in one class can access a member of another class. . (Using reference). 2.Whether a subclass can inherit a member of its superclass (use extend and access it by inheritance iff the member should be visible)
* If a subclass inherits a member, the subclass has the member.
* Exam Watch: You need to know the effect of different combinations of class and member access (such as a default class with a public variable). To figure this out, first look at the access level of the class. If the class itself will not be visible to
another class, then none of the members will be either, even if the member is declared public. Once you’ve confirmed that the class is visible, then it makes sense to look at access levels on individual members.
* Public: When a method or variable member is declared public, it means all other class regardless of the package can access the member.(assuming the class itself is visible).
* If a member of its superclass is declared public, the subclass inherits that member regardless of whether both classes are in the same package.
* In the subclass, you can invoke the super class method without reference. (Without the dot operator). Using reference also wont hurt.
* The reference this always refers to the currently executing object. this reference is implicit.
* Private: Members marked private can’t be accessed by code in any class other than the class in which the private member is declared.
* A private member is invisible to any code outside the member’s own class.
* Question: What about a subclass that tries to inherit a private member of its superclass? A subclass can’t inherit it.
* A subclass can’t see or use or even think about private members of its super class.
* You can however have a matching method in the subclass with the same method name in the super class. It is simply a method that happens to have the same method name as the private method in the super class. Overriding rules does not apply.
* On the job: In practice it’s nearly always best to keep all variables private or protected. If variables needs to be changed programmers should use public accessor methods.
* Question: Can a private method be overridden by a subclass? No. Since the subclass cannot inherit the private method, it therefore cannot override the method. (Overriding depends on inheritance).
* Default Members: A default member can be accessed only if the class accessing the member belongs to the same package.
* Protected Members: A protected member can be accessed (through inheritance) by a subclass even if the subclass is in the different package.
* Note: You cannot access protected member using object reference. The subclass cannot use the dot operator on the superclass reference to access the protected member.
* Question But what does it mean for a subclass-outside the package to have access (visibility to a superclass (parent) member? It means the subclass inherits the member.
* The subclass can only see the protected member through inheritance. For a subclass outside the package, the protected member can be accessed only through inheritance.
* Question: What does a protected member look like to other classes trying to use the subclass-outside-the-package to get the subclass’ inherited protected superclass member?
Say for ex: class A is in Package A, class B is in Package B. class B is accessing the protected member x in class A. What happens if some class say class C in the same package B has a reference to class B wants to access the member variable x (protected member in class A).
How does that protected member behave once the subclass has inherited it? Does it maintain its protected status, such that classes in the Child’s package can see it?
No. Once the subclass-outside-the package inherits the protected member, that member (as inherited by the subclass) becomes private to any code outside the subclass.
The bottom line: when a subclass-outside-the-package inherits a protected member, the member is essentially private inside the subclass, such that only the subclass’ own code can access it.
* Question: What about default access for two classes in the same package? It works fine. Remember that default members are visible only to the subclasses are in the same package as the superclass.
Local Variables and Access Modifiers
* Question: Can access modifiers be applied to local variables? No.
* Exam Watch: There is never a case where an access modifier can be applied to a local variable, so watch out code like the following.
class Foo {
void doStuff() {
private int x = 7;
this.doMore(x);
}
}
You can be certain that any local variable declared with modifier cannot compile. In fact there is only one modifier can ever be applied to a local variables-final.
Visibility
Public
Protected
Default
Private
From the same class
Yes
Yes
Yes
Yes
From any class in the same package
Yes
Yes
Yes
No
From any non-subclass class outside the package.
Yes
No
No
No
From a subclass in the same package
Yes
Yes
Yes
No
From a subclass outside the same package.
Yes
Yes
No
No

NonAccess Member Modifiers
* Final, abstract, transient, synchronized, strictfp, native.
* Final Methods: The final keyword prevents a method from being overridden in a subclass.
* Final Arguments: Method arguments are essentially the same as the local variables. Can declare the method arguments as final.
* Abstract Methods: An abstract method is a method that has been declared but has to be implemented. This method contains no functional code. An abstract method does not even have the curly braces for the functional implementation, instead it closes with the semicolon.
* You can have abstract class with no abstract methods.
* Any class that extends abstract class has to implement all abstract methods of the superclass. Unless the subclass is also abstract.
* Rule is: The first concrete (means Non abstract) subclass of an abstract class must implement all abstract methods of the superclass.
* If the subclass is abstract it is not required to implement the abstract methods of the superclass, but it is allowed to implement any or all of the superclass abstract methods.
* Exam Watch: Look for concrete classes that don’t provide method implementations for abstract methods of the superclass. For example, the following code won’t compile:
public abstract class A {
abstract void foo();
}
class B extends A {
void foo(int I) {
}
}
Class B won’t compile because it doesn’t implement the inherited abstract
method foo(). Although the foo(int I)method in class B might appear
to be an implementation of the superclass’ abstract method, it is simply
an overloaded method (a method using the same identifier, but different
arguments), so it doesn’t fulfill the requirements for implementing the
superclass’ abstract method.
* Note: A method can never ever be marked as both abstract and final or both abstract and private. Think!!
Abstract methods has to be implemented, whereas final and private methods cannot be overridden by the subclass.
* Abstract methods cannot be marked as synchronized, strictfp or native, static.
* Synchronized Methods: The synchronized keyword indicates that the method can be accessed by only one thread at a time.
* Synchronized keyword can be applied only to methods.
* Synchronized modifier can be paired with any of the four access control levels. (private, public, default, protected).
* Synchronized can be paired with final but not with abstract
* Native Methods: The native keyword indicates that a method is implemented in a platform dependent language such as C.
* Native can never be combined with abstract.
* Native can be applied only to methods, not to classes , variables.
* Strictfp Methods: Strictfp forces floating point operations to adhere IEE754 standard.
* Strictfp can modify a class or nonabstract method declaration and that a Variable can never be declared strictfp.
Variable Declarations
* Instance Variables: Instance variables are defined inside the class but outside the method. Onlu initialized when the class is instantiated.
* Instance variables can use any of the four access levels. Can be marked Final, transient, abstract, strictfp, native, synchronized.
* Local variables: Local variables are declared within the method. Means variables is not just initialized within the method but also declared within the method. It starts its life inside the method, it’s also destroyed when the method has completed.
* Local variables are always on the stack, not the heap. Get clarified. Pg:34
* Local variable declarations can’t use most of the modifiers such as public, transient, volatile, abstract, static.
* Local variables can be marked final.
* Before using the local variable it should be initialized.
* Local variables don’t get default values.
* Local variables can’t be referenced outside the method in which it is declared.
* It is possible to declare the local variable with the same name as an instance variable. That’s known as shadowing.
The following (but wrong) code is trying to set an instance variable’s value using a parameter:
class Foo {
int size = 27;
public void setSize(int size) {
size = size; // ??? which size equals which size???
}
}
Use the keyword this. The this keyword always always refers to the object currently running.
* Final Variables: Impossible to reinitialize the variable once it has been initialized. For primitives, once the variable is assigned a value, the value can’t be altered.
* Question: What does it mean to have a final object reference? A reference variable marked final can’t ever be reassigned to refer to a different object. The data within the object, however can be modified but the reference variable cannot be changed.
* You can use final references to modify the object it refers to, but you can’t modify the reference variable to make it refer to a different object.
* Remember there are no final objects, only final references.
* Exam Watch: Look for code that tries to reassign a final variable, but don’t expect to be obvious. For example, a variable declared in an interface is always implicitly final, whether you declare it that way or not. So you might see code similar to the following:
interface Foo {
Integer x = new Integer(5); // x is implicitly final
}
class FooImpl implements Foo {
void doStuff() {
x = new Integer(5); // Big Trouble! Can’t assign new object to x
}
}
The reference variable x is final. It is an interface variable, they are always implicitly public static final. Final can’t be reassigned, that in the case of interface variables, they are final even if they don’t say it out loud. The exam expects you to spot any attempt to violate this rule.
* Transient Variables: If you mark an instance variable as transient, (Remember: only you can declare final to the local variable) you’re telling the JVM to skip this variable when you attempt to serialize the object declaring it.
* Serialization lets u save an object by writing its state to a special IO writing stream.
* For exam you need know: Transient can be applied only to instance variables.
* Volatile Variables: The volatile tells the JVM that a thread accessing the variable must always reconcile its own private copy of the variable with the master copy in the memory.
* For exam you need know: Volatile can be applied only to instance variables.
* Static variables and methods: Can use a static method or a variable without having any instances of that class at all.
* Variables and methods marked static belong to the class.
* The rule is, a static method of a class can’t access a nonstatic (instance) member—method or variable—of its own class.
* Exam Watch: One of the mistakes most often made by new Java programmers is attempting to access an instance variable (which means nonstatic variable) from the static main()method (which doesn’t know anything about any instances, so it can’t access the variable). The following code is an example of illegal access of a nonstatic variable from a static method:
class Foo {
int x = 3;
public static void main (String [] args) {
System.out.println(“x is “ + x);
}
}
Understand that this code will never compile, because you can’t access a
nonstatic (instance) variable from a static method. Just think of the compilersaying, “Hey, I have no idea which Foo object’s x variable you’re trying to print!”
Remember, it’s the class running the main()method, not an instance of the
class. Of course, the tricky part for the exam is that the question won’t look
as obvious as the preceding code. The problem you’re being tested for—
accessing a nonstatic variable from a static method—will be buried in code
that might appear to be testing something else.

For example, the code above would be more likely to appear as
class Foo {
int x = 3;
float y = 4.3f;
public static void main (String [] args) {
for (int z = x; z < ++x; z--, y = y + z) { // complicated looping and branching code } } So while you’re off trying to follow the logic, the real issue is that x and y can’t be used within main(), because x and y are instance, not static, variables! The same applies for accessing nonstatic methods from a static method. The rule is, a static method of a class can’t access a nonstatic (instance) member— method or variable—of its own class. v Accessing Static Methods and Variables: Access a static method or static variable is to use the dot operator on the class name, as opposed to on a reference to an instance variable. v Also java allows you to access the static members using the object reference variable. v Static methods can’t be overridden. v Things you can mark as Static: Methods, Variables, Top-level nested classes. v Things you can’t mark as Static: Constructors (constructor is used only to create instances), Classes, Interfaces, Inner Classes, Inner class methods and variables, Local variables. v Static method cannot access an instance (non-static) variable. (remember about main method) v Static method cannot access a non-static methods. v Static method can access a static method and variable. v Static members are per-class as opposed to per-instance. Source files, Package, Declarations and Import Statements. v There can be only one package statement per source code file. v Can have only one pubic class per source code file. v On the Job: Putting multiple classes in the same source code file makes it much harder to locate the source for a particular class and makes the source code less reusable. v Exam Watch: The exam uses a line numbering scheme that indicates whether the code in the question is a snippet (a partial code sample taken from a larger file), or complete file. If the line numbers start at 1, you’re looking at a complete file. If the numbers start at some arbitrary (but always greater than 1) number, you’re looking at only a fragment of code rather than the complete source code file. For example, the following indicates a complete file: 1. package fluffy; 2. class Bunny { 3. public void hop() { } 4. } whereas the following indicates a snippet: 9. public void hop() { 10. System.out.println(“hopping”); 11. } v Exam Watch: You might see questions that appear to be asking about classes and packages in the core Java API that you haven’t studied, because you didn’t think they were part of the exam objectives. For example, if you see a question like class Foo extends java.rmi.UnicastRemoteObject { /// more code } don’t panic! You’re not actually being tested on your RMI knowledge, but rather a language and/or syntax issue. If you see code that references a class you’re not familiar with, you can assume you’re being tested on the way in which the code is structured, as opposed to what the class actually does. In the preceding code example, the question might really be about whether you need an import statement if you use the fully qualified name in your code (the answer is no, by the way). v Exam Watch: Look for syntax errors on import statements. Can you spot what’s wrong with the following code? import java.util.Arraylist.*; // Wildcard import import java.util; // Explicit class import The first import looks like it should be a valid wildcard import, but ArrayList is a class, not a package, so it makes no sense (not to mention making the compiler cranky) to use the wildcard import on a single class. Pay attention to the syntax detail of the import statement, by looking at how the statement ends. If it ends with .*;(dot, asterisk, semicolon), then it must be a wildcard statement; therefore, the thing immediately preceding the .*;must be a package name, not a class name. Conversely, the second import looks like an explicit class import, but util is a package, not a class, so you can’t end that statement with a semicolon. v Question: What happens if you have two classes with the same name in two different packages, and you want to use both in the same source code? You should use fully qualified name. v static public void main (String whatever []) { } – This method is perfectly legal. The most important point for the exam is to know that not having the “able-to-run” main() method is a runtime, rather than compiler error. A class with a legal, nonstatic main()method, for example, will compile just fine, and other code is free to call that method. But when it comes time to use that class to invoke the JVM, that nonstatic main()method just won’t cut it, and you’ll get the runtime error. v Interface Implementation: Exam Watch: You must know how to implement the java.lang.Runnableinterface,without being shown the code in the question. In other words, you might be asked to choose from a list of six classes which one provides a correct implementation of Runnable. Be sure you memorize the signature of the one and only one Runnableinterface method: public void run() { } For any other interface-related question not dealing with Runnable, if the specification of the interface matters, the interface code will appear in the question. A question, for example, might show you a complete interface and a complete class, and ask you to choose whether or not the class correctly implements the interface. But if the question is about Runnable, you won’t be shown the interface. You’re expected to have Runnablememorized! v Interface: What a class can do without saying anything about how the class will do it. v Think of an interface as a 100-percent abstract class. Like an abstract class interface defines abstract methods. v But while an abstract class can define both abstract and non-abstract methods. v Interface can have only abstract methods. v Interface has very little flexibility in how the methods and variables defined in the interface are declared. The rules are strict, but simple. v All interface methods must be implemented and must be marked public. v What you declare in the interface : interface bounceable{ void bounce(); void setbouncefactor(int bf); } v What the compiler looks: interface bounceable{ public abstract void bounce(); public abstract void setbouncefactor(int bf); } v All interface methods are implicitly public and abstract. v Interface methods must not be static. v You do not need to actually type the public and abstract modifiers in the method declaration, but the method is still always public and abstract. v All variables defined in the method must be public static final. In other words, interfaces can declare only constants, not instance variables. v Because interface methods are abstract, they cannot be marked as final, native, synchronized, strictfp. v An interface can extend one or more interfaces. v An interface cannot extend anything but another interface. v An interface cannot implement another interface or class. v Interface must be declared with the keyword interface. v public interface Rollable {} , public abstract interface Rollable { } – Both are legal. Since interfaces are implicitly abstract. v Exam Watch: Look for interface methods declared with any combination of public,abstract, or no modifiers. For example, the following five method declarations, if declared within an interface, are legal and identical! void bounce(); public void bounce(); abstract void bounce(); public abstract void bounce(); abstract public void bounce(); The following interface method declarations won’t compile: final void bounce(); // final and abstract can never be used static void bounce(); // interfaces define instance methods private void bounce(); // interface methods are always public protected void bounce(); // (same as above) synchronized void bounce(); // can’t mix abstract and synchronized native void bounce(); // can’t mix abstract and native strictfp void bounce(); // can’t mix abstract and strictfp v By placing the constants in the interface, any class that implements the interface has direct access to the constants, just as if the class had inherited them. v Interface constants must always be public, static, final. v Any variable declared in the interface must be implicitly is – a public constant. v Exam Watch: Look for interface definitions that define constants, but without explicitly using the required modifiers. For example, the following are all identical: public int x = 1; // Looks non-static and non-final, but isn’t! int x = 1; // Looks default, non-final, and non-static, but isn’t! static int x = 1; // Doesn’t show final or public final int x = 1; // Doesn’t show static or public public static int x = 1; // Doesn’t show final public final int x = 1; // Doesn’t show static static final int x = 1 // Doesn’t show public public static final int x = 1; // Exactly what you get implicitly Any combination of the required (but implicit) modifiers is legal, as is using no modifiers at all! On the exam, you can expect to see questions you won’t be able to answer correctly unless you know, for example, that an interface variable is final and can never be given a value by the implementing (or any other) class. v While implementing the interface – Provide concrete implementations for all methods from the declared interface. – Follow all the rules for legal overrides – Declare no checked exceptions on implementation methods other than those declared by the interface methods or subclass of those declared by the interface method. – Maintain the signature of the interface method, and maintains the same return type. But does not have to declare the exceptions declared in the interface method declaration. v An implementation class can itself be abstract. When the implementation class itself is abstract, it simply passes the buck to its first concrete subclass. v Exam Watch: Look for methods that claim to implement an interface but don’t provide the correct method implementations. Unless the implementing class is abstract, the implementing class must provide implementations for all methods defined in the interface. v A class can extend more than one interface You can extend only one class but implement many interface. v An interface can extend another interface, but cannot implement another interface. v public interface Bounceable extends Moveable { } - Perfectly legal. The first concrete implementation class of Bounceable interface, should implement all the methods of Bounceable Plus all the methods in Moveable interface. v An interface can extend more than one interface. Think!!! Question: A class is not allowed to extend multiple classes. If it does then it would be multiple inheritance But why in Interface interface Bounceable extends Moveable, spherical { void bounce(); void setBounceFactor(int bf); } class Ball extends Bounceable – this class has to implement all the methods in Bounceable, Moveable, Spherical. If not then class Ball is marked abstract. v Exam Watch: Look for illegal use of extends and implements. The following shows examples of legal and illegal class and interface declarations. 1. class Foo { } 2. class Bar implements Foo { } 3. interface Baz { } 4. interface Fi { } 5. interface Fee implements Baz { } 6. interface Zee implements Foo { } 7. interface Zoo extends Foo { } 8. interface Boo extends Fi { } 9. class Toon extends Foo, Button { } 10. class Zoom implements Fi, Fee { } 11. interface Vroom extends Fi, Fee { } 1. Ok. 2. No. Class cannot implement another class. 3. Ok. 4. Ok. 5. No. Interface cannot implement another interface. It can only extend another interfaces. 6. No. Interface cannot implement another class. 7. No. Interface cannot extend class. It will extend only interfaces. 8. Ok. 9. No. Class cannot extend two classes. 10. Ok. Class can implement multiple interface. 11. Ok. interface can extend multiple interfaces. Burn these in, and watch for abuses in the questions you get on the exam. Regardless of what the question appears to be testing, the real problem might be the class or interface declaration. Before you get caught up in, say, tracing a complex threading flow, check to see if the code will even compile. (Just that tip alone may be worth your putting us in your will!) (You’ll be impressed by the effort the exam developers put into distracting you from the real problem.) (How did people manage to write anything before parentheses were (was?) invented?) v v Assertions: Let you to test your assumptions during development, without the expense (in both your time and program overhead) of writing exception handlers for exceptions that you assume will never happen once the program is out of development and fully deployed. v v

Tuesday, December 5, 2006

Questions for getting knowlwdge in Java conti......

16.)Can a reference variable of an interfece holds the address of an object of a class that implements that interface
Example
class X implements Y
{
//Method Implementations of Interface
public static void main(String args[])
{
Y y=new X();
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Yes. reference variable of an interfece holds the address of an object of a class that implements that interface


17.)Explain the advantages of OOPs with the examples.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The main advantage of using OOPs is that it supports Inheritance.Inheritance is the process of acquiring the properties and methods from one entity to another entity
Other advantages are abstraction(data hiding) and polymorphism.

ENCAPSULATION: It is the data binds together code and the data it manipulates and keeps them safe from outside interference and misuse. When data and code are linked together in this fashion, an object is created. In other words an object is the device that supports encapsulation.
POLYMORPHISM: The name itself suggests that “POLY” stands for many and “MORPHISM” stands for forms. Polymorphism is the quality that allows one name to be used for two or more related but technically different purposes. In general giving multiple interfaces to a function or an operator is called “POLYMORPHISM”.INHERITANCE: Inheritance is the process by which one object can acquire the properties of another. The best example for this is C,C++, and JAVA languages itself. Java is being derived from C++ which in return is being derived from C from where it inherits all the capabilities of C,C++ and also add the features of its own.


18.) difference between data abstraction vs encapsulation
----------------------------------------------------------------------------------------------------------------------------------------------------------------

Abstraction is achieved through encapsulation. Abstraction solves the problem in the design side while encapsulation is the implementation.
In Short Abstraction is "Collection of data" and Encapsulation is "Exposure (or grouping) of data in appropriate access specifier".


19.)difference between class and object?


Class is like a template where as object is the implementation of the template. By using the same we can have any no .of implementations

Class is the blueprint to construct a building. object is the physical constructed building . we can construct any no .of buildings with the same blue print.

20.)What are there to update the instance variables?
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Setter methods (or) simply called as mutators can update the instance variables


21.)Can instance variables can be overridden?
----------------------------------------------------------------------------------------------------------------------------------------------------------------

Instance variables can not be overridden. Only methods which a subclass extends its super class and methods from the interface can be overridden.

22.)How many polymorphism are there in OOPS and how many supports Java?
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Coercion,overloading,parametric, and inclusion among these java supports only three


23.) How come jvm know what to do with marker interface I mean we are not implementing any method. Will it know with the name of the marker interface what to do?
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
jvm does not know bout marker interfaces. yr code, or sun knowns bout marker interfaces via reflection.

24.) explain the difference between response.sendRedirect and forward methods
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

when client gives req to a servletà response.sendredirect() method partially delegates the control to another servlet or jsp by giving request to that,and recieves the response from that servlet.then our requested servlet includes the response of its own and another servlet,and that willbe passed to the client.that means client doesnot knowthat control goes to another servlet,that willbe happened internally.

incaseof forward() method control permanently goes to another servlet.the output ofthe first servlet willbe discarded.The only response of redirected servlet willbe displayed to the browser.


25.) How can we make a hashmap synchronised by using the collections framework
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
There is a static method in Collection Using which u can obtain a Synchronized version of HashMap..

Map m = Collections.synchronizedMap(new HashMap(...));

Questions for getting knowlwdge in Java

LANGUAGE MAKES SIMPLE
1.)What is the difference between the static variable and local variable?
________________________________________________________________________________
a) static variable just it is global variable.We access this variable through this classname. variable;
where in case of local variable u can access that particular method alone u can't access that variable where u declare other than that method.
b) static variable has a single copy of the object where as an ordinary variable store a indivdual element

2)What is the difference between abstract class and interface?
--------------------------------------------------------------------------------

a) . abstract classes have a concrete Method while interface have no method implementation.
b). abstract class comes in to inherit chain while interface don’t
c). Abstract class may have concrete methods which need not require to be overridden but In Interface all methods need to be overridden.


3.) Whats the difference between length() and .length?...
--------------------------------------------------------------------------------

length() is the method and length is the keyword. length() is used to find the length of the string in String object. length is used to know the size of array.


4.)Take 2 classes.i.e., Class A,Class B.In Class B declare constructor as Private.But I have to access Class A using the constructor in Class B.How is it possible?One interviewer told that Through getInstance() method it's possible to access Class A.eEven Class B declare as Private.How is it possible?
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Yes its true when u have method in ClassB as getInstance() which return the new ClassB(). Here it is about creating singleton object of ClassB which returns only one instance at give point.
5.)What is the use of super keyword. give me an example.
--------------------------------------------------------------------------------
With the keyword 'super', you can access the overridden methods and data.
public class A {
int i = 0;
void fun(){
i = 9;
}
}
class B extends A {
int j = 0;
void fun() {
j = 8;
super.fun ();
j = j - i;
}
}

6.)When to extend Thread Class and when to implement Runnable Interface
----------------------------------------------------------------------------------------------------------------------------------------------------------------

I will always prefer the Runnable Interface. Reason being, if we extend to Thread class, then we cannot extend any other class from our application. So if there is a class that can provide useful functionality to us, then we cannot extend it and use its "protected" fields.Moral of the Story - Gud Designer will "ALWAYS" use Runnable interface.

7.)Why local variable doesn't initialized by default while class variable may be?
----------------------------------------------------------------------------------------------------------------------------------------------------------------

A constructor initializes an object immediately upon creation. If we do not explicitly define a constructor for a class, then java creates a default constructor for the class. The default constructor automatically initializes all instance variables to zero. So local variables doesn't initialized by default while class variable does.

8.)Does Java have pass by value or pass by reference or both?Please Explain it with example
----------------------------------------------------------------------------------------------------------------------------------------------------------------
a.)"pass by value" and "pass by ref" are both defined in java. In pass by value technique.....a copy of aurguments are passed to the method......( ex: sum(10,5) and in pass by ref technique.....a ref to the values are passed to the method.....(exp: sum(a,b))
b.) java has both i.e. pass by value and pass by ref. When primitive types are passed, they are passed by value but when objects are passed, they are passed by ref. And reference itself is passed by value.

9.)What is the difference between function/method synchronization and object synchronization?Explain with an example
----------------------------------------------------------------------------------------------------------------------------------------------------------------
synchronize method

To synchronize an entire method, you just include the synchronized keyword as one of the method qualifiers, as in:

class syncDemo{

synchronized void test{

//your synchronized code

}

synchronize object

To create a synchronized object, you use the synchronized keyword with an expression that evaluates to an object reference, as in

class syncDemo{

void test{

synchronized (this){

//your synchronized code

}

function or method synchronization synchronizes entire method i.e.synchronized void MyMethod(){...}this will place a lock on the object until current thread finishes execution. This ensures that MyMethod is always accessed by a single thread at a time.But consider this,void MyMethod(){.... someOtherMethod();..}Here you might need to just make sure that call to someOtherMethod() is synchronized, so instead of making entire method synchronized, you just make a synchronized block around someOtherMethod()void MyMethod(){....synchronize{ someOtherMethod();}..}This improves perfomance by locking object for shorter duration.Of-course you need to analyze your code correctly for doing this. There is not straight forward answer as to when to use Synchronize method vs Synchronize block.

10.)When to use a CharacterStream or a ByteStream
----------------------------------------------------------------------------------------------------------------------------------------------------------------

In general, we should use the character stream classes when working with characters or strings, and use the byte stream classes when working with bytes or other binary objects.


11.)What is the difference between a class and Interface?
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Interfaces (pure behavior) and classes (state and behavior). Interfaces are used in Java to specify the behavior of derived classes. Where in classes we usually declare and initialize variables and these will be called as state and concrete methods are said to be behavior in classes.

12.)What is the significance of Marker interface? Why are we using, even though it has no method?
----------------------------------------------------------------------------------------------------------------------------------------------------------------

The marker methods specifies the functionality of a class depending upon the need. For example if a method needs to be serialised then it should implement serialiazable which doesnt have any methods to define, but an indication for the JVM that this class instatiates objects which can be inserted into an byte stream

13.)What is meant by Serialization and Externalization?
--------------------------------------------------------------------------------

Marker Interface is used by java runtime engine (JVM) to identify the class for special processing.

Serialization is a process of converting state of an object to stream of bytes that can be sent over network or can be stored in a file or in database to be reconstructed into Object Later when required. Remember EJB spec, all EJB (Session or Entity) implements Serializable interface indirectly, in case of Statefull session bean it can be Passivated or Activated (Persisted by writing it to file system or Database this is done by container).


Externalization is same as Serialization except that WriteObject() and ReadObject() method are called by JVM during Serialization and Serialization of object. One thing you can do with Externalization is that you can store extra information into object like STATIC variables and transient variables or you can add more information if you have any business need. One good example is compressing and uncompressing of data to send it through network or converting one format to other like a BMP image to JPEG or GIF format.


14.)What is the difference between Serializalble and Externalizable interface?
----------------------------------------------------------------------------------------------------------------------------------------------------------------
When you use Serializable interface, your class is serialized automatically by default. But you can override writeObject() and readObject() two methods to control more complex object serailization process. When you use Externalizable interface, you have a complete control over your class's serialization process.

15.)String a=new String("A");
String b=new String("A");
String c="A";
String d="A";

Then which of the following returns true?

1. if(a==b)
2. if(b==c)
3. if(c==d)
4. if(d==a)
----------------------------------------------------------------------------------------------------------------------------------------------------------------


the if(c==d) gives the true only. the reason behind this is whenever you create the object by not using "new" operator like string a="A" then it will search whether is there any object with same content.if there is any same object then it simply assigns to previous existing object.but when you create the object with new then it will create new obj every time.thats all


15.) What is the difference between an interface and abstract class?
----------------------------------------------------------------------------------------------------------------------------------------------------------------

In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.
Abstract class means
1)We can have concreate methods and abstract methods
2) We can give implementation for concreate methods.
Interfaces means
1)we could not have concreate methods. All the methods are abstract methods implicitly.
2)And those methods allows only public access specifier only. It wont
allow any final, static keywords with methods

Thursday, November 9, 2006

AJAX Powers Web 2.0 Growth

AJAX Powers Web 2.0 Growth

By Stephen Bryant October 5, 2005 Reporter's Notebook: JavaScript, once a much-maligned scripting language, is now at the forefront of the Web 2.0 technology evolution. But where's the business model for AJAX-powered applications?
SAN FRANCISCO—Jesse James Garrett leaned on a stool at the front of the Web 2.0 Conference's AJAX workshop here Wednesday, sipping from a bowler glass and striking a Joycian figure with his goatee and horn-rimmed glasses.
The man who coined the term AJAX (Asynchronous JavaScript and XML)—"In the shower I think, right, Jesse?" said Peter Merholz, a co-worker at Adaptive Path LLC—agreed with publisher Tim O'Reilly's Web 2.0-as-paradigm-shift argument .
"The applications 2.0 revolution isn't a technological revolution at all, it's a revolution in our understanding of how to use these technologies better," Garrett said.
To wit, the panel didn't discuss any revolutionary business models. Instead, they spoke about how the AJAX-powered Web 2.0 revolution (or evolution, if you prefer) is changing existing business models and Web sites for the better.
Garrett said that Google, for example, "applied these technologies to problems people thought had been solved," such as how best to handle e-mail and maps.
What got everybody's attention about Google's applications is that the company figured out how to deploy these new technologies without compromising technology.

The Web 1.0 party line was always, "Sure, we can make this app look cool if the user has Internet Explorer or if they have the right plug-in." Today, that concern has almost been obviated.
But Garrett and Merholz stressed that collaboration between designers and developers is key. Whereas it was very difficult to hang yourself with HTML alone, today's technologies require greater teamwork to pull off.
But where's the business case and the ROI (return on investment) with AJAX-powered apps? The panel, which included Joe Chung of Allurent, Inc., Evan Goldberg from NetSuite Inc. and Peter Kaminski of Socialtext Inc., didn't have a clear answer.
"The business owners … understand the technology now and have become the drivers," Chung said. "But to really understand the ROI, you have to bring in statisticians and do a controlled study. Your hunches aren't good enough anymore."
Read a roundup here of the current top 10 Web 2.0 apps for the office.
Chung demonstrated Allurent Inc.'s shopping cart application, which took advantage of Flash to improve upon the typically frustrating online shopping experience.
Merholz added, "Right now the business case is largely around the experience. It's going to have to get more finalized, and pretty soon, to drive adoption."
Of course, there are roadblocks to widespread AJAX adoption. One of the largest is the lack of development tools available to AJAX developers.
"I think the lack of development tools, yeah, that's a roadblock," Garrett said. "But the market opportunity is just too big. I think that if you're in an organization that has a real strong tech culture that goes all the way up to the top level, there's going to be some hesitancy to do anything with JavaScript. They're going to need to be convinced."
Part of the reason, the panelists agreed, was that JavaScript was much abused, and thus almost universally maligned, after its debut.
So where does the business opportunity exist right now? Everywhere. AJAX is an evolutionary approach to technology because it allows developers to do redo basically every application on the Web, as Google did with Gmail and Google Maps.
Click here to read about Google's Weblog search.
Garrett and Merholz debuted the pre-alpha of their site traffic analyzer, MeasureMap. Interestingly, the application combines AJAX techniques and Flash technology.
"Flash is definitely one of these technologies that has proven itself," Garrett said. "Flash certainly has better development tools than JavaScript developers have available to them."
Garrett added that Flash is great at data visualization and direct manipulation of data. What's more, applications like MeasureMap and technologies like sIFR demonstrate that Flash can be used without the presence of a Flash UI. Flash and AJAX can talk to each other, and the user never even has to know.
The future of AJAX technologies may be influenced, in part, by how organizations accommodate the disparate Flash and JavaScript development cultures.
Meanwhile, several companies wanting to be part of the Web 2.0 evolution made announcements today.
Attentiontrust.org announced the Attention Trust Recorder, a Firefox extension that records browsing history and saves it both to your desktop and to the Attention Trust service. You can then choose which parts of that history you want to share with service providers.
Flock announced that it is expanding its beta group from a few hundred to a few thousand new users today as well. Interested parties can sign up at flock.com.
And Zevents announced its social event manager/calendar today, just in time to hear Yahoo Inc. announce that it has acquired upcoming.org.

Tuesday, October 31, 2006

A Tribute to the Great women

It broke our heart to lose you, But you did not goalone Part of us went with you, the day God called youhome. A million times I've thought of you A milliontimes we've cried If loving could have saved you. Youwould have never died Forgive me GOD, We'll alwaysweep for the Grandmother. We loved but could not keep.You will forever remain in our heart and in ourthoughts. Thank you for being such a great teacher,best friend, and loving grand mother.We miss & think of you every day Nannamma.you are anAngel in Heaven..Love from all your Family..... Narendra.

Do what ever you say

Issue a command the person in the browser will do it.
http://www.subservientprogrammer.com/main.aspx