https://docs.google.com/spreadsheet/ccc?key=0Al4BjJlYg8vEdEdRVDBTVXV3c1R5UHNnUm5Zekl6cEE#gid=0https://docs.google.com/spreadsheet/ccc?key=0Al4BjJlYg8vEdEdRVDBTVXV3c1R5UHNnUm5Zekl6cEE#gid=0
Java Docs
Thursday, October 25, 2012
Monday, October 22, 2012
AWT notes

Component | Event it generates |
---|---|
Button, TextField, List, Menu | ActionEvent |
Frame | WindowEvent |
Checkbox, Choice, List | ItemEvent |
Scrollbar | AdjustmentEvent |
Mouse (hardware) | MouseEvent |
Keyboard (hardware) | KeyEvent |
Listener Interface | Component |
---|---|
WindowListener | Frame |
ActionListener | Button, TextField, List, Menu |
ItemListener | Checkbox, Choice, List |
AdjustmentListener | Scrollbar |
MouseListener | Mouse (stable) |
MouseMotionListener | Mouse (moving) |
KeyListener | Keyboard |
example
public class ButtonDemo extends Frame implements ActionListener { public ButtonDemo() { Button btn = new Button("OK"); btn.addActionListener(this); add(btn); } public void actionPerformed(ActionEvent e) { String str = e.getActionCommand(); } } |
Wednesday, August 8, 2012
Understanding Page Directives
Three Key Directives
<% @ page ..... %>
<% @ include .... %>
<% @ tag lib ... %>
Page Directive :
format <% @ page attribute="value" %>
Attributes :
buffer
Note :
Refference:
http://www.oreillynet.com/pub/a/oreilly/java/news/jsptips_1100.html
Tuesday, July 3, 2012
Interesting one liners
1. A method can be defined both private an final the compiler will not throw error. Declaring a method both final and private is redundant since private methods by default cannot be overridden.
2. What happen if you declare a static method as final
Ans : Stops you from declaring a static method with the same name and parameter types in a derived class
3. "this" keyword cannot be used inside static methods/blocks
4. Static final variables will have to be initialized with the declaration and cannot be left blank
5. final variables can initialized only during declaration or in the consturctor
6. Anonymous classes do not have constructors
7. few methods in Object class are-
clone, equals,hashcode,finalize,toString, notify,notifyall,wait
8. how to call garbage collector explicitly
System.gc();
9.Difference btw Interface & Abstract
all methods in the Interface and implicitly abstract
10. How to create a deamon thread
setDeamon()
Sythetic Field
http://tns-www.lcs.mit.edu/manuals/java-api-1.1beta2/guide/innerclasses/html/innerclasses.doc.html#19265
2. What happen if you declare a static method as final
Ans : Stops you from declaring a static method with the same name and parameter types in a derived class
3. "this" keyword cannot be used inside static methods/blocks
4. Static final variables will have to be initialized with the declaration and cannot be left blank
5. final variables can initialized only during declaration or in the consturctor
6. Anonymous classes do not have constructors
7. few methods in Object class are-
clone, equals,hashcode,finalize,toString, notify,notifyall,wait
8. how to call garbage collector explicitly
System.gc();
9.Difference btw Interface & Abstract
all methods in the Interface and implicitly abstract
10. How to create a deamon thread
setDeamon()
Sythetic Field
http://tns-www.lcs.mit.edu/manuals/java-api-1.1beta2/guide/innerclasses/html/innerclasses.doc.html#19265
Servelet
Life Cycle of a Servelet
a) A server loads and initializes the servlet by init () method.
b) The servlet handles zero or more client’s requests through service() method.
c) The server removes the servlet through destroy() method.
What is session tracking and how do you track a user session in servlets?- Session tracking is a mechanism that servlets use to maintain state about a series requests from the same user across some period of time. The methods used for session tracking are:
a) User Authentication - occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized username and password.
b) Hidden form fields - fields are added to an HTML form that are not displayed in the client’s browser. When the form containing the fields is submitted, the fields are sent back to the server.
c) URL rewriting - every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change.
d) Cookies - a bit of information that is sent by a web server to a browser and which can later be read back from that browser.
What is Server-Side Includes (SSI)?-
Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page. This is accomplished using a special internal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension is requested. So HTML files that include server-side includes must be stored with an . shtml extension.
e) HttpSession- places a limit on the number of sessions that can exist in memory. This limit is set in the session. maxresidents property.
Q: | What are the common mechanisms used for session tracking? | |
A: | Cookies SSL sessions URL- rewriting |
What is the difference between doGet() and doPost()?
#
| doGet() | doPost() |
---|---|---|
1
| In doGet() the parameters are appended to the URL and sent along with header information. | In doPost(), on the other hand will (typically) send the information through a socket back to the webserver and it won't show up in the URL bar. |
2
| The amount of information you can send back using a GET is restricted as URLs can only be 1024 characters. | You can send much more information to the server this way - and it's not restricted to textual data either. It is possible to send files and even binary data such as serialized Java objects! |
3
| doGet() is a request for information; it does not (or should not) change anything on the server. (doGet() should be idempotent) | doPost() provides information (such as placing an order for merchandise) that the server is expected to remember |
4
| Parameters are not encrypted | Parameters are encrypted |
5
| doGet() is faster if we set the response content length since the same connection is used. Thus increasing the performance | doPost() is generally used to update or post some information to the server.doPost is slower compared to doGet since doPost does not write the content length |
6
| doGet() should be idempotent. i.e. doget should be able to be repeated safely many times | This method does not need to be idempotent. Operations requested through POST can have side effects for which the user can be held accountable. |
7
| doGet() should be safe without any side effects for which user is held responsible | This method does not need to be either safe |
8
| It allows bookmarks. | It disallows bookmarks. |
Creating a servelet :
1.Servlet needs to extend HttpServlet
2. Constructor calls super()
3. Has doGet() and doPost() methods
4. Web.xml has to updated with an entry for the servlet
ex :
<servlet>
<description></description>
<display-name>TestServeletOne</display-name>
<servlet-name>TestServeletOne</servlet-name>
<servlet-class>com.cisco.capacityplanning.servelet.TestServeletOne</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServeletOne</servlet-name>
<url-pattern>/TestServeletOne</url-pattern>
</servlet-mapping>
url for testing this servlet:
http://localhost:8080/CapacityPlanning/TestServeletOne
Saturday, June 30, 2012
Singleton Class
1.Define the constructor as private
2.Expose a method that can be used to create the object - getObject()
3. Synchronize the exposed method getObject method
4. Define a private Static - which would store a single instance.
Nested Class
Todo :
1. how do nested classes act when overridden
Non Static Nested Inner Class :
To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax:
______________________________________________
Note :
1. how do nested classes act when overridden
- Non-static nested classes are also called inner classes have access to other members of the enclosing class, even if they are declared private
- Static nested classes do not have access to other members of the enclosing class
- As a member of the
OuterClass
, a nested class can be declaredprivate
,public
,protected
, or package private
Why Use Nested Classes?
There are several compelling reasons for using nested classes, among them:- It is a way of logically grouping classes that are only used in one place.
- It increases encapsulation.
- Nested classes can lead to more readable and maintainable code.
Non Static Nested Inner Class :
To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax:
OuterClass.InnerClass innerObject = outerObject.new InnerClass(); An instance ofInnerClass
can exist only within an instance ofOuterClass
and has direct access to the methods and fields of its enclosing instance. Also, because an inner class is associated with an instance, it cannot define any static members itself. Static Nested Class : As with class methods and variables, a static nested class is associated with its outer class. And like static class methods, a static nested class cannot refer directly to instance variables or methods defined in its enclosing class — it can use them only through an object reference.
OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass();
Type | Scope | Inner |
---|---|---|
static nested class | member | no |
inner [non-static] class | member | yes |
local class | local | yes |
anonymous class | only the point where it is defined | yes |
Note :
- Interfaces are never inner .
- Non Static inner classes cannot define static variables ex static int abc =0 will result in compile time error
- Non Static inner classes can define compile time constatns ex static final int abc=0
Subscribe to:
Posts (Atom)