IT Certificaions

Google Cloud Platform

Thursday, August 30, 2012

JavaScript: Remove all backslash (\) from a String in JavaScript

How to remove  all backslash (\) from a String in JavaScript

Solution:
function replaceAllBackSlash(targetStr){
      var index=targetStr.indexOf("\\");
      while(index >= 0){
          targetStr=targetStr.replace("\\","");
          index=targetStr.indexOf("\\");
      }
      return targetStr;
  }

Google App Engine: Cloud Storage: java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;I)V

Uncaught exception from servlet
java.lang.NoSuchMethodError: org.objectweb.asm.ClassReader.accept(Lorg/objectweb/asm/ClassVisitor;I)V
    at com.sun.jersey.spi.scanning.AnnotationScannerListener.onProcess(AnnotationScannerListener.java:133)
    at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner$1.f(FileSchemeScanner.java:86)
    at com.sun.jersey.core.util.Closing.f(Closing.java:71)
    at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scanDirectory(FileSchemeScanner.java:83)
    at com.sun.jersey.core.spi.scanning.uri.FileSchemeScanner.scan(FileSchemeScanner.java:71)
    at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:223)
    at com.sun.jersey.core.spi.scanning.PackageNamesScanner.scan(PackageNamesScanner.java:139)
    at com.sun.jersey.api.core.ScanningResourceConfig.init(ScanningResourceConfig.java:80)
    at com.sun.jersey.api.core.PackagesResourceConfig.init(PackagesResourceConfig.java:104)
    at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:78)
    at com.sun.jersey.api.core.PackagesResourceConfig.<init>(PackagesResourceConfig.java:89)
    at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:700)
    at com.sun.jersey.spi.container.servlet.WebComponent.createResourceConfig(WebComponent.java:678)
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:203)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:440)
    at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:263)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:685)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:202)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:171)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:123)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:447)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:452)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:458)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:698)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:336)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:328)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:456)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:679)

---------------------------------------------------------------------------------------------------


    Solution: Please remove dupliacte asm.jar if it is there from WEB-INF/lib folder and then upload code again on google app engine nad then run.

Friday, August 24, 2012

facebook share button


-------------------------------------------------------------------
1) Using javascript
 <div >
<script>var fbShare = {google_analytics: 'true', size: 'small',url: 'http://knowledgeserve.in'}</script>
    <script src="http://widgets.fbshare.me/files/fbshare.js"></script>
</div>

-------------------------------------------------------------------------------

2) You can use FBML.....

      <div id="fb-root"></div>
        <script>(function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=APP_ID"; // appId must be valid; 
                                                                                        //  for example: APP_ID=172095742912464

          fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));</script>
        <fb:share-button type="button" href=" http://knowledgeserve.in ">
        </fb:share-button>

Tuesday, August 21, 2012

FileZila error: 421: Could not connect to server


FileZila connection error:

421 Sorry, cleartext sessions are not accepted on this server. 
Error: Could not connect to server

--------------------------------------------------------------

Please add a ftpes:// before the domain name

Previous One,
host : domain.com
username : abcd
pass : ******
port : 21


Change this,
host : ftpes://domain.com
username : abcd
pass : ******
port : 21

Friday, August 10, 2012

Timesgroups interview questions: Servlet lifecycle : who called destroy() method of servlet

destroy() method is called by the servlet container. It is to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service() method have exited or after a timeout period has passed.
    public void destroy() {
      anyDB = null;
    }
How container knows that all the threads are exited and where we specify the timeout period for a servlet.

For more, visit link: http://docs.oracle.com/javaee/1.4/tutorial/doc/Servlets12.html

Timesgroups Interviews questions: Iterate hashmap in java

You can use the following different ways.....

1: Iterating HashMaps over entries using For-Each loop.

Use this if you need both map keys and values in the loop.

Map<String, String> map = new HashMap<String, String>();
for (Map.Entry<String, String> entry : map.entrySet()) {
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}
-------------------------------------------------------------------
2. Filterating over keys or values using for-each loop.......

If you need only keys or values from the map, you can iterate over keySet or values instead of entrySet.

Map<Integer, Integer> map = new HashMap<Integer, Integer>();
//iterating over keys only
for (Integer key : map.keySet()) {
    System.out.println("Key = " + key);
}

//iterating over values only
for (Integer value : map.values()) {
    System.out.println("Value = " + value);
}
-----------------------------------------------------------
3.: Iterating using Iterator......with the help of entrySet() method

Using Generics:

Map<Integer, Integer> map = new HashMap<Integer, Integer>();
Iterator<Map.Entry<Integer, Integer>> entries = map.entrySet().iterator();   //entrySet() returns set
while (entries.hasNext()) {
    Map.Entry<Integer, Integer> entry = entries.next();
    System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
}

Without Generics:

Map map = new HashMap();
Iterator entries = map.entrySet().iterator();        //entrySet() returns set
while (entries.hasNext()) {
    Map.Entry entry = (Map.Entry) entries.next(); 
    Integer key = (Integer)entry.getKey();
    Integer value = (Integer)entry.getValue();
    System.out.println("Key = " + key + ", Value = " + value);
}

-------------------------------------------------------------------------------

4: Iterating over keys and then searching for values with the help of keys(Not good).

Map<Integer, Integer> map = new HashMap<Integer, Integer>();
for (Integer key : map.keySet()) {
    Integer value = map.get(key);
    System.out.println("Key = " + key + ", Value = " + value);
}

Times group Interview questions: Method overloading/overriding

is it overloading? will it compile, if not then why ?
  public void show(String a){
    //.....
    //...
  }



   public int show(String a){
    //.....
    //...
   }


 Solution: It is not mothod overloading as argument list must be different. It will not compile and compiler will give duplicate method error.

Timesgroup interview questions: Self JOIN with an example

A self-join is used when a table is joined (compared) to itself.  It means when you need to compare values in a column with other values in the same column in the same table. 
Use of self-joins:  obtaining running counts and running totals in an SQL query.

 Example: select emp1.name,emp1.salary,emp1.state   from employee emp1,employee emp2
  where emp1.state=emp2.state;


  ---------------------------------------------------
  Name                     Salary          State
  ---------------------------------------------------
  Rajesh Singh           10250            Delhi
  Kavita                     10850                Delhi
  Kamal Singh           15250            Delhi
  Rajesh Singh           20250            Haryana
  Manish Kumar        15100            Haryana
  ---------------------------------------------------