MY mENU


Saturday 17 March 2012

Super() keyword

"super()" method :

                super() method is used to call super class constructor from sub class constructor to create super class object when subclass object is created. Suppose we have a super class and sub class having a method with same name, then from subclass if we want to acess the super class method, we need to use the suer keyword for accesing the super class method. We can acess the super class members from subclass as super.variable, super.method(), super(values) ...
ex:

class SupCls {
sameMethod(){ }
}
class SubCls {
sameMethod() { }
// calling super class method
super.sameMethod();
}

We can call SuperClass Constructor From SubClass Constructor explicitly using super(); or super(parameter list);


- With super(), the SuperClass Default Constructor is called.

- With super(parameter list), the SuperClass Argumented Constructor with a matching      parameter list is called.

- Invocation of a SuperClass Constructor must be the first line in the SubClass Constructor.

- If a SubClass Constructor does not explicitly invoke a SuperClass Constructor, the Java Compiler automatically call to the Default Constructor of the SuperClass. And if theSuperClass does not have a Default Constructor, we will get a compile-time error.


- Compiler places super() method call in all constructors at the time of compilation, if there is no super() or this() method call is placed explicitly.

Developer should place super() method call in below two cases:
- if super class does not contain no-arg constructor.
- if developer wants to create super class object with parameterized constructor.

In the above two cases developer should define constructor in sub class with explicit super() method class by  passing agument of type same as super class constructor parameter type.

Rule: Inheritance can only be implemented if super class has a visible constructor. It means other than private constructor.

Super() method rules: Identify is inheritance possible in below cases?

Case1: Empty super class
class Example{}

class Sample extends Example{}


Case2: Super class with explicit no-arg constructor
class Example{
       Example(){
          Sopln("No-arg")


               }   }

class Sample extends Example{}


Case3: Super class with explicit parameterized constructor
class Example{
     Example(int a){
            Sopln("No-arg")


              }   }

class Sample extends Example{}


Case4: super class with private constructor
class Example{
         private Example(){
               Sopln("No-arg") ;
                        }      }
class Sample extends Example{
  Sample(){
       Sopln("sample parm");  
       }
   public static void main(String arg[]){


              Sample s=new Sample();
                 }}

Case5: super class with private constructor and visible parameterized constructor
class Example{
         private Example(){
               Sopln("No-arg") ;
                        }     
       Example(){
                Sopln("Pram");
                  } }
class Sample extends Example{
  Sample(){
       Sopln("sample parm");  
}
   public static void main(String arg[]){


              Sample s=new Sample();
}}
  1. Super keyword is used to call immediate parent.
  2. Super keyword can be used with instance members i.e., instance variables and instance      methods.
  3. Super keyword can be used within constructor to call the constructor of parent class.
Use of Super Keyword:
  • Use of super keyword is to access the hidden data variables of the super class hidden by the sub class.
  • super keyword most useful to handle situations where the local members of a subclass hide the members of a super class having the same name.
  • Its a non-static variable used to store super class object reference through current sub class object.
A sample program about using this and super keywords:


public class Demo {
Demo(){
super();
System.out.println("in Demo Constructor");
}
public void m1(){
System.out.println("in m1 of Demo Class");
}
public void m2(){
System.out.println("in m2 of Demo Class");
this.m1();
}
public void m3(){
System.out.println("in m3 of Demo Class");
}
public static void main(String[] args) {
Demo d=new Demo();
d.m1();
d.m2();
d.m3();

Demo sd=new SubClassOfDemo();
sd.m1();
sd.m2();
sd.m3();
}
}
class SubClassOfDemo extends Demo
{
public SubClassOfDemo() {
super();
}
public void m1(){
System.out.println("in m1 of SubClasssDemo Class");
}
public void m2(){
super.m2();
System.out.println("in m2 of SubClasssDemo Class");
}}

Remote Assistance


Run into computer problems and don't know how to get help? You can ask an expert to remotely connect to you over the internet.
Many of us may have had our computer suffer from a hardware or software problem. Usually the way out is to either call a computer expert over or take the system to the nearest service centre. However, you can easily get help for common issues using a remote connection. 

Both Windows and MAC have built-in remote assistance features that allow you to share control of your desktop/laptop remotely with an expert over the Internet, who can then examine and solve the issue. 

WINDOWS PCS 

The Remote Assistance feature first appeared in Windows XP. To enable this feature, go to the Control Panel > System and in the window that opens up, click on the Remote Tab. Check the box that says 'Allow Remote Assistance Invitations'. You can invite an expert you know to connect to your system via a secure remote connection by sending an email or by using Windows Messenger. 

Once connected, the expert will be able view your desktop screen, control your mouse and chat with you side-by-side in the remote assistance window. Note that you will need to share control of your system with the expert by clicking on the 'Take Control' button on top (a security feature). Once the expert solves your problem, you can disconnect the remote assistance session and start using your system. 

MAC 

On a MAC, there are two ways to provide remote control of a system for assistance. The first (and simpler) method is by using iChat/Messages. Just add the user to your chat list, start a conversation and select 'Screen Share Enabled' from the Video menu on top. 

The second way is to go to System Preferences > Sharing. Check the box that says 'Screen Sharing' and click on the computer settings button. Check both the options in the pop-up window. You will also need to specify a password for accessing your system. The expert will be required to enter the password to connect to your system. The one issue with this method is that it is really easy to use over a local network, but if the expert is in another location, you need to know how to configure your networking devices (port forwarding). 

WEBSITES 

TEACHPARENTSTECH.ORG 
This website has a collection of howto videos depicting various day-today used programs and functions of a PC/MAC. You can view the videos and even email them to less tech savvy family members or friends. 

LIFEHACKER.COM 
Lifehacker has a dedicated section (http://goo.gl/hA0jY) of easy-to-understand & emailable articles that feature step-by-step explanations of how to go about setting up a new device or perform various functions on a PC/MAC. 

HELP THROUGH A BROWSER 
CHROME REMOTE DESKTOP 
Google's Chrome browser offers a free add-on called 'Chrome Remote Desktop' — it allows remote control of one computer by another irrespective of the operating system. Both the systems just need to have Chrome with the add-on installed. It generates an authentication code on the host computer, which has to be entered in the remote computer to be able to get secure remote access. 

SOFTWARE TEAM VIEWER 

This multi-platform (Windows, MAC, Linux) software allows remote control, collaboration as well as file sharing between two connected computers. It is free to download for non-commercial use, you can download iOS and Android apps and it also secures the remote connection using 256-bit encryption. Get it from : www.teamviewer.com 

CROSSLOOP 

It offers an unlimited connection to another computer with the free version and also allows for a remote reboot. You can get an Android app for remote access plus perform unlimited file transfers between connected computers. Works with (and between) Windows and MAC. Get it from : www.crossloop.com 

LOGMEIN FREE 

This offers remote control for Windows or MAC from other computers or iOS devices. Using LogMeIn, you can also remotely wake up a computer from sleep. The free version uses 256-bit encryption for remote connection but does not allow file transfers. However, you can still use remote access to open and view files. Get it from : http://secure.logmein.com 

MIKOGO 

Mikogo offers many more features than just remote control of a computer. It offers session recording, multi-monitor support as well as an option to pause the session. The free account only allows for 14 days of trial usage. (It costs $13/month for the basic plan) Get it from : www.mikogo.com 

JOIN.ME 

Join.me allows access and control of a remote computer via a web browser. The remote PC is required to install a small software that gives you an access code. The access code allows anyone to connect via the Join.me website. The remote PC can then share control, chat or even set up a voice call over the internet. Get it from : http://join.me 

Android 5.0

Google Android 5.0 Coming Soon:
Even as Google's Android 4.0 (Ice Cream Sandwich) operating system is yet to fully take off, the news of its successor is already doing rounds. 
According to a report in Taiwan's DigiTimes,Google is readying the launch of Android 5.0 dubbed Jelly Bean in the second quarter of this year. 

The report, quoting Taiwan-based supply chain makers, reveals that Google is reportedly asking users to adopt Android 5.0 and Windows 8 in the same tablet PC. Software giant Microsoft is scheduled to unveil a test version of its Windows 8 operating software later this month. 

While Android 4.0 brings a bunch of new features for tablets as well as smartphones, Android 5.0 is likely to be further optimized for tablet PCs. The report states that Google plans to integrate its Chrome system functions to push dual-operating system designs. 
The report further claims that Google will let vendors add Android 5.0 to a Windows 8-based tablet or notebook, giving them the option to switch between the operating systems without a reboot. 

While most of the Android phone manufacturers have updated their Ice Cream Sandwich release schedules, it is yet to see how the OS climbs in popularity in comparison to its closest rival Apple's iOS5. 


Among other things, Android 4.0 offers a brand new font system called Roboto; lets users take screenshots without rooting the smartphone or installing any third-party apps and transcribes words instantly into text. 

The current OS also features Android Beam, based on NFC (Near Field Communication) which allows two Android smartphones to securely exchange Web pages, contacts, media or even applications. 

Browsing History


For most people, searching the web is limited to just entering a bit of text into a search box. Here we show you how to search faster, more accurately and have some fun while doing it too.
Google 
Launched in 1997, this search engine with a minimalist design has grown in a way that a few would have imagined. It is adopted by multiple browsers as the engine for their top search bar and is also used as a homepage by various browsers.
Tips, tricks and easter eggs
1. Search in Klingon — If you're a Star Trek fan, head to http://google.com/intl/xx-klingon to view Google in Star Trek's Klingon language. 2. Search as Elmer Fudd — Looney Tunes fans can view Google in the way Elmer Fudd speaks by vis iting http://google.com/intl/xx-elmer. 3. Play Pacman in Google — http://google.com/ pacman has a mini version of the game to play. 4. Experimental Google - http://google.com/experimental will show you options to enable keyboard shortcuts for a faster web search.
Yahoo 
Although Yahoo has been in the search business since 1994, they have recently entered into a deal with Microsoft for their search engine to be powered by Bing. The transition is expected to be complete sometime during 2012.
Tips, tricks and easter eggs
1. Yahoo Yokel — Open www.yahoo.com (not the Yahoo India site) and click on the exclamation mark in the Yahoo logo on top to hear the Yahoo yokel. 2. Compose email from search box — In the search box type "!mail abc@xyz.com" (where abc@xyz.com is a complete email ID) to directly compose a mail with that email ID in the 'to' field (You need to be signed in to Yahoo for this to work). 3. Search within a website — Yahoo allows you to search within other sites from its search page. Just type "!sitename query" (for example !wiki Vegas).
Bing 
Bing has been through its share of transitions right from when it started off as MSN Search in 1999. Over the years it was changed to Windows Live Search and Live Search before Microsoft finally settled on Bing in 2009.
Tips, tricks and easter eggs
1. Get the full version of Bing — The localised version of Bing's search page shows a trimmed down version. Go to www.bing.com/worldwide.aspx and set your language to US-English to see the en tire interactive search page.
2. Get search results as RSS feeds — You can subscribe to search results as RSS feeds by adding "&format=rss" to the search results page URL. 3. Results for linked files — You can search a specific site for linked files by adding "contains:filetype" in your query (for eg site: bing.com contains:doc). Search Engines for Specific Needs
For Music 
Use Midomi to discover new music, listen to samples or just sing/hum into your microphone to find the name of a song you've heard before. They also offer free iOS & Android apps.
www.midomi.com
Deep Web Search 
Dogpile combines most relevant search results of your query from Google, Yahoo & Bing to deliver results faster. You can even add it to your browser or get a toolbar.
www.dogpile.com
For Images 
Bookmark PicSearch to search for images from all over the web. It offers easy ways to streamline your search plus image dimensions & file size are clearly mentioned upfront.
www.picsearch.com
Medicine Related 
Probably the largest medical resource on the internet, WebMD can check on symptoms, offer food advice, tips on parenting and pregnancy and lists common names for drugs.
www.webmd.com
For Videos 
Blinkx has over 35 million hours of video stored — all searchable, but you can also view categories, ask it to show you current news, entertain you or create a custom channel.
www.blinkx.com
Automatic Search 
Wolfram Alpha is not a search engine; it's a computational knowledge engine. Use it for conversions, stats, fact finding or just enter anything that you want to know about in the search box.
www.wolframalpha.com.

HttpRequestHeader & HttpResponseHeader


List of httpRequestHeader & httpResponseHeader :

httpRequesHeaders are:

1.cookie
2.host
3.referer
4.accept
5.accept-language
6.accept-encoding
7.keep-alive
8.user-agent
9.connection
10.if-modified-since

“keep-alive” request header value holds a number (300) indicating for how many seconds the connection between browser & web-server should be alive.

httpResponseHeaders are:

1.Location
2.refresh
3.set-cookie
4.cache-control/pragma
5.content-encoding
6.content-lenth
7.content-type
8.last-modified

“location” Instead of sending response to requested browser /source browser which has given request, if you want to send to new browser then use httpResponseHeader called location.

Important response codes in Servlets

Frequent http response codes:

100-199: warnings or Information

200-299: success
300-399: Redirection
400-499: Incomplete processing
500-599: server error
200-success & document of response follows as web page response.
201-success but no response body.
301- Given request is moved to other web resources or websites permanently.
302: Given request to web-resource is forwarded or moved to other Web-resources of website temporarity.

Note: The http response status code 300-399 comes if given request is forwarded to other web sites from the original & actually requested web-sites.

401: The user who has given request if not authorised web-site / web-resource [error].
404: Requested web-resource is not found
500: Problem in web-xml code

Servlet Mapping

Servlet mapping:

The servlet mapping defines an association between a URL pattern and a servlet. The mapping is used to map requests to Servlets.

Servlet Questions- Part4

What is the important packages in Servlet Api ?
            According to JAVA language API means set of classes & interfaces that comes in the form of packages.  Servlet –API:
1. javax.servlet:  (This package definers several classes and interfaces to develop sevlets from the scratch irrespective of any protocol )

2. javax.servlet.http: (This package defines several classes and interfaces to develop http based servlets.)


I can access internet hosted websites by typing domain name like www.myjavahub.com.

But our class room web-applications are not accessed in the same manner more over we are typing technical URL(http://localhost:8080/webappname/url) to access the web-resource of web-application can you explain the answer?            
      The ISP[Internet service provider] maintains a special registry called ”DNS registry” containing domain names mapped with the URL’s to open the home pages of website. When user gives request to web-site by typing “domain name” the actual URL. will be collected from the DNS registry using that URL it interacts with real web-resource of web-application using the internet network. Due to this reason we can just type domain name which acts as a logical name to access web-sites while working with websites that are hosted on the Internet. In class room level web-application since we don’t take the help of domain naming registry so we need to type complete URL having port no web-application name & etc technical details to interact with web-resources. Protocol is a set of rules followed by both parties who want to participate in communication.

http is a protocol that is given to transfer hypertext [text with hyper links ] between web browser software & web server software, vice-versa.

Can we write a default constructor for servlet ?
 Yes.But not recommended.  Because by default container generating default constructor.so we no need to write explicitly.

what is the use of HttpServletRequest ?
1. retrive html form parameres
2. retrive html header inforamtion
3. retrive cookies.
4. retrive html form parameres

 What is the use of HttpServletResponse object ?
Http response:
1. S: http response status code
2. C: http rensonse content
3. H: http response headers.
4. add cookies to the response.

How to refresh the webpage generated by servlet automatically at regular intervals?
response.set header(“refresh”,”5”);
by mention above statement , the browser will refresh automatically for every “5” seconds.

What is a buffer/cache & how to disable the buffer available in the browser while displaying response of a web-resource [servlet] in the browser window?Buffer is a temporary memory residing in browser & stores the response data given by web-server
By default browser enable buffering while receiving response from a web-server.
To disable this we can use “cache-control/pragma” response Headers as shown below from the service () method of servlet.
res.setHeader(“cache-control”,”no-cache”);//for http1.1 based web server
(OR)
res.setHeader(“pragma”,”no-cache”);//for http1.o based servers.

HttpservletRequest, HttpServletResponse are the interfaces. How did you say request, response parameters of service() methods as objects?     
             An interface reference variable points to implementation class object. Reference variable also becomes indirect object of implementation class.
In any servlet service(request,response) method request is not the object of HttpServletRequest interface, it is the object of class that implements HttpServletRequest interface. Similarly response is not the object of HttpServletResponse interface, it is the object of a class that implements HttpServletResponse. Both these classes will be given by the underlying Web-server/Application server.

what are different mime types are there in servlets ?
The following is the list of some common mime types:
1.text/html à html document
2.text/xhtml à xhtml document
3.text/xml à xml document
4.image/GIF à gif image fiel
5.text/jpeg à jpeg image file
6.application/pdf à pdf file
7.application/jar à jar file

What is the difference between PrintWriter stream object ServletOutputStream object .which are useful to write response content to browser from servlet.
PrintWriter is a character stream & sends the response to browser in the form of characters.
ServletOutputStream is a byte stream & sends the response to browser in the form of binary data.
Both stream objects must be prepared using response object & associated with response object.
We cannot see both stream objects in a single servlet.
To get PrintWriter object the code is
PrintWriter pw = res.getWriter();
To get ServletOutputStream object the code is
ServletOutputStream out = res.getOutputStream();
Character stream object is good for sending text response And Byte stream object is good for sending binary information like images as response.

Note :between these two PrintWriter is best one.

What are the important resources in Servlet WebApplication ?
1.static content
[All the static information we have to place with in the context root either directly or indirectly]
2.jsp pages
3.Servlet classes
4.Deployment Descriptor (web.xml)
5.Tag Liabraries.
6.Jar files
7.Java class Files

How many web.xml files in possible in one web application ?
for every web application we have to maintain only one web.xml and should be placed directly in WEB-INF folder.

ServletConfig and ServletContext Objects

ServetConfig object?

1. for every servlet web container creates one ServletConfig object to hold servlet level configuration information.
2. ServletConfig interface defines several methods to access this configurations information.
Ex: getInitParameter()
getInitParameterNames();
getSerlvetName();
getServletContext()

ServletContext object ?
1. for every web application web container creates one ServletContext object to hold application level configuration information.
2. ServlerContext interface defines several methods to access this information.
Ex: getInitParameter();

Difference between ServletConfig and ServletContext object ?




                ServletConfig
           
             ServletContext


ServletConfig object means it is the object of a class that implements ServletConfig interface.[ javax.servlet.ServletConfig]


Servlet context object means it is the object of a class that implements javax.servlet.ServletContext interface.

1 per servlet object so it is called right-hand object for servlet object.


It is one per web-application         

Every Servlet contains one ServletConfig object.

Common for all the web-resources of a web-application. So it is called Global memory of the web-application.


Web container creates ServletConfig object for servlet object when servlet object is created. web container destroys ServletConfig object  when its servlet object is destroyed.

web-container creates ServletContext object when web-application is deployed and destroys ServletContext  object when web-application  stopped (or)reloaded (or) undeployed.


ServletConfig object is useful to pass additional data to the servlet and to read additional data from the servlet like “logical name “ given to servlet and etc…

Using ServletContext object we can gather following details
1)Name and version of the underlying web server.
2)servlet API version implemented by web server.
3)Logical Names of all servlets available in web-application 4)”context parameters”   available in the web-application.