Tech Me More

To quench our thirst of sharing knowledge about our day to day experience & solution to techincal problems we face in our projects.

Advertise with us !
Send us an email at diehardtechy@gmail.com

Tuesday, October 14, 2014

HashSet in collection framework


HashSet

HashSet is the direct subclass of Set interface , HashSet doesn’t allow duplicates element insertion and insertion order is not preserved.

  1.  Underlined data structure is HashTable.
  2. HashSet doesn't allow duplicates.
  3.  Insertion order is not preserved.
  4.  Null insertion is allowed.
  5.  Heterogeneous objects are allowed. 
  6. Implements Serializable and clonable interfaces.

Constructor in HashSet

HashSet hs=new HashSet();  // creates an empty HashSet


HashSet hs=new HashSet(int initialCapacity); 

//Creates and empty HashSet with passed initialCapacity and default load factor 0.75.

HashSet hs=new HashSet(Collection c); 

//Creates a HashSet representation of Passed collection object.

HashSet hs=new HashSet(int initialCapacity, float loadFactor); 

//creates an empty HashSet with given initialCapacity and given loadFactor.

Example:

import java.util.*;
class HashSetDemo 
{
 public static void main(String[] args) 
 {
  HashSet hs=new HashSet();
  hs.add(10);
  hs.add(20);
  hs.add(30);
  hs.add(10);
  hs.add("Hello");
  hs.add(null);
  hs.add(new HashSetDemo());
  System.out.println(hs);
  System.out.println(hs.remove(30)); /*removes the passes argument object from 
           the HashSet and returns true, false otherwise.*/
  System.out.println("Total number of elements in the HashSet "+hs.size());
  hs.clear(); //clear the entire HashSet 
  System.out.println(hs);
  
 }
}

Output:



Neosoft Technologies Ltd hiring 1-4 years experience as java developers


Company Name : Neosoft Technologies Ltd

Location :Hyderabad

Position : Java/J2ee Developer

Experience: 1 to 4 Year

Apply here : Click to apply 

Skills Required



  • Application/UI development in Java, JSP, Servlets, JDBC.
  • J2EE, JSP, Tiles, UML Methodology.
  • Extensive coding experience on IDEs like Netbeans / JBuilder / Eclipse, experience with HTML, JavaScript, XML/XSL/XSLT.
  • Must have sound knowledge of Frameworks: Spring, Struts, Hibernate, Swing, JSF, EJB.
  • Database –(MYSQL, Oracle, PostgreSQL)

Friday, October 10, 2014

Flipkart big billion day. What went wrong and what we should learn from it.

They named it as big billion day but many visitors named it as big fool day because of the unwanted performance issue and technical problems in the back end of flipkart application . 

Here is our point on what went wrong and what should we learn from it.

They deployed best of app servers , extend their system capabilities and work force to an extreme but an unfortunate show of technically unfeasible web application, no matter how decent front end of your web application looks but if the application back end is not strong outcome can be worse than big billion day as flipkat.Computers and computer science technology are the great resources and can bring you never imagined admiration. But if you don't respect technology they can make you stand in a situation where you never want to go.

But as the saying goes every breakdown bring some message/lesson associated with it, this crash of flipkart application is a best trigger for all fellow IT people, future technocrats and architects to learn, nurture and craft a system which will be sustainable even in the circumstances of extreme traffic or load.

I support flipkart for the dedication and confidence they have created; I can only imagine how many sleepless nights flipkart and their team have spent to bring it on a forefront. It takes unlimited patience, confidence and dedication to turn something big into reality. The bitter results are the best critics which teach us to learn and learn and push ourselves to the beyond.

P.S. this post is not a criticism of an e-commerce giant but a learning prospect for performance engineers, quality assurance engineers and classy developers, it is also a big business opportunity for independent software testing organizations.

Tuesday, October 7, 2014

9 Key Interfaces of Collection framework and Collection framework Hierarchy

Collection framework in Java


When we want to represent a group of individual object as a single entity we should choose Collection. 



Difference between Collection and Collections

Collection is an interface, whereas Collections is a class in java. Collection is treated as base interface in Collection framework, whereas Collections class consists exclusively of static methods that operate on or return collections. Collections class is defined in java.util package.


9 Key Interfaces of Collection framework

  • Collection
  • List
  • Set
  • SortedSet
  • NavigableSet
  • Queue
  • Map
  • SortedMap
  • NavigableMap

s       Collection framework Hierarchy

        






How to start with servlets, a guide for beginners.

How to start with Servlets, Write a servlet program to print the name coming from a HTML form.

Before we start with servlets , make sure you have following software installed.
  1. Apache Tomcat 7.0
  2. Java 1.7 or higher

Create a folder structure as shown below under C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps directory.




  1. Create a file say HelloWorld.java and placed it in the classes folder.
  2. import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    public class HelloWorld extends HttpServlet 
    {
     public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
     {
      String name=request.getParameter("t1");
      response.setContentType("text/html");
      PrintWriter ps=response.getWriter();
      ps.print("Hello "+name);
     }
    }
  3. compile the HelloWorld.java file.
  4. edit the web.xml file as given below.

  5. <?xml version="1.0" encoding="ISO-8859-1"?>
    <!--
     Licensed to the Apache Software Foundation (ASF) under one or more
      contributor license agreements.  See the NOTICE file distributed with
      this work for additional information regarding copyright ownership.
      The ASF licenses this file to You under the Apache License, Version 2.0
      (the "License"); you may not use this file except in compliance with
      the License.  You may obtain a copy of the License at
    
          http://www.apache.org/licenses/LICENSE-2.0
    
      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.
    -->
    
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
      version="3.0"  metadata-complete="true">
    
      <display-name>Welcome to Tomcat</display-name>
      <description>Welcome to Tomcat</description>
    
      <servlet>
        <servlet-name>FirstSer</servlet-name>
        <servlet-class>HelloWorld</servlet-class>
      </servlet> 
    
      <servlet-mapping>
        <servlet-name>FirstSer</servlet-name>
        <url-pattern>/DisplayName.do</url-pattern>
      </servlet-mapping>
    
    </web-app>
    
  6. Create a Hello.html file and place it in HelloWorld i.e. root folder.

  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> First App</title>
     </head>
     <body>
     <form action="DisplayName.do">
     <center>
     <h1>Please enter your name </h1>
      <input type="text" name="t1"><input type="submit" value="Submit">
      </center>
      </form>
     </body>
    </html>
    
  8. Run the Tomcat Server.
  9. Navigate to the following URL.
    http://localhost:8080/HelloWorld/Hello.html

    You should see the Hello.html web page on your browser.
    Hello.html


  10. Enter your Name in the text field and click submit.
  11. You should see the result something like below.



If you run into any error, please feel free to reach us.