Hub Of Geekz

  • Home
  • About Me
  • Contact Us
  • Home
  • Languages
    • C++
    • Java
    • Perl
    • Prolog
    • Bootstrap
  • Database
    • SQL
    • PL/SQL
  • Study
    • Java
      • Java Collection
      • Java Concurrency
      • Java Interview Questions
      • Java Networking
    • Number System
  • Kavita
  • Entertainment
    • Hinglish Cafe
    • Videos
    • Jokes
  • Windows Tricks
  • How To

Wednesday, 17 December 2014

The Leader

 Earthcare Foundation NGO     08:49     Social Services     No comments   

Who is leader??
What makes anyone a leader??
What should be the properties of a leader??
Do you want to become a leader??
Answer to first question,Who is leader??
So according to me a leader is anyone who leads others and able to convince them.
In other words,A leader is someone who organizes a group of people and then achieve a common goal with them.
Now next question, What makes anyone a leader??
If anyone is able to convince others and complete the task with help of others then he has the ability to become a leader.
Now next question,What should be the properties of a leader??
According to me a leader should have the following properties:
Self confidence
Ability to convince other
Control on anger(Cool Minded)
Now next question,Do you want to become a leader??
So do you want to become a leader.If yes then at least you have to follow the above steps.
If you have other views about leadership then comment.I would like to receive the comments. 


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Sunday, 26 October 2014

ServletContext in Servlet

 Earthcare Foundation NGO     12:40     Java, Servlet     No comments   

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>ServletContext</title>
</head>
<body>
<form action="MyServlet1">
<input type="submit" value="Go to Servlet1">
</form>
</body>

</html>


MyServlet1.java



import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class MyServlet1 extends HttpServlet {
private static final long serialVersionUID = 1L;
     
 
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter pw=response.getWriter();
ServletContext context=getServletContext();
context.setAttribute("name", "Abhi");
pw.println("We are in Servlet1 <br>");
pw.println("<a href='MyServlet2'>Click Me</a>");
pw.close();
}


}


MyServlet2.java



import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet2 extends HttpServlet {
private static final long serialVersionUID = 1L;
  
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


response.setContentType("text/html");
PrintWriter pw=response.getWriter();
ServletContext context=getServletContext();
String name=(String)context.getAttribute("name");
pw.println("We are in Servlet2<br>");
pw.println("Welcome "+name);
pw.close();
}


}


web.xml

 <servlet>
    <description></description>
    <display-name>MyServlet1</display-name>
    <servlet-name>MyServlet1</servlet-name>
    <servlet-class>MyServlet1</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>MyServlet1</servlet-name>
    <url-pattern>/MyServlet1</url-pattern>
  </servlet-mapping>
  <servlet>
    <description></description>
    <display-name>MyServlet2</display-name>
    <servlet-name>MyServlet2</servlet-name>
    <servlet-class>MyServlet2</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>MyServlet2</servlet-name>
    <url-pattern>/MyServlet2</url-pattern>
  </servlet-mapping>






Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

sendRedirect() method in Servlet

 Earthcare Foundation NGO     12:10     Java, Servlet     No comments   

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>sendRedirect() Method Example</title>
</head>
<body>
<form action="SearchServlet" method="get">
<input type="text" name="name">
<input type="submit" value="Google Search">
</form>
</body>
</html>

SearchServlet.java



import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SearchServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
     
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String name=request.getParameter("name");
response.sendRedirect("https://www.google.co.in/#query="+name);
}

}



web.xml

<servlet>
    <description></description>
    <display-name>SearchServlet</display-name>
    <servlet-name>SearchServlet</servlet-name>
    <servlet-class>SearchServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>SearchServlet</servlet-name>
    <url-pattern>/SearchServlet</url-pattern>
  </servlet-mapping>
</web-app>








Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Wednesday, 22 October 2014

Servlets in Java

 Earthcare Foundation NGO     11:08     Java     No comments   

Servlet Program



import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
     

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

response.setContentType("text/html");
PrintWriter pw=response.getWriter();
String name=request.getParameter("firstName");
pw.println("Welcome "+name);
pw.close();
}


}

Html Page

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Index Page</title>
</head>
<body>
<form action="MyServlet" method="get">
First Name:<input type="text" name="firstName"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>


Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>ServletE</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>MyServlet</display-name>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>MyServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/MyServlet</url-pattern>
  </servlet-mapping>
</web-app>


















Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

HashMap in Java

 Earthcare Foundation NGO     10:08     Java     No comments   

import java.util.*;


public class HashMapImp {

public static void main(String[] args) {

//If we take key as object
//Then key can be any datatype

Map<Object,Object> hMap=new HashMap<Object,Object>();
hMap.put(1, 1);
hMap.put(2, 3.0);
hMap.put(3.0, "Hello");
hMap.put(1, 2);
hMap.put("Abhi", 1);
System.out.println(hMap);

//Map contains Integer as key
//And String as value
Map<Integer,String> map=new HashMap<Integer,String>();

map.put(1, "Hi");
map.put(2, "Abhi");
map.put(3, "Hello");
map.put(1, "I");
map.put(3,"Abhi");
System.out.println(map);

}

}




Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

HashSet In Java

 Earthcare Foundation NGO     09:57     Java     No comments   

import java.util.*;


public class HashSetImp {

public static void main(String[] args) {

//General HashSet
Set<Object> hSet=new HashSet<Object>();
hSet.add(1);
hSet.add(3.0);
hSet.add("Hello");
hSet.add(1);
hSet.add("My");
hSet.add(3.0);
System.out.println(hSet);

//Specific HashSet of String
Set<String> set=new HashSet<String>();
set.add("Hello");
set.add("My");
set.add("My");
System.out.println(set);


}

}



Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Friday, 17 October 2014

Different ways to delete elements from ArrayList

 Unknown     23:21     Java, Java Interview Questions     No comments   

import java.util.ArrayList;
import java.util.Iterator;


public class ArrayDeletion {

public static void main(String[] args) {

ArrayList<String> list=new ArrayList<String>();
list.add("a");
list.add("b");
list.add("c");
list.add("d");

ArrayList<String> list1=new ArrayList<String>();
list1.add("a");
list1.add("b");
list1.add("c");
list1.add("d");

ArrayList<String> list2=new ArrayList<String>();

list2.add("a");
list2.add("b");
list2.add("c");
list2.add("d");

ArrayList<String> list3=new ArrayList<String>();
list3.add("a");
list3.add("b");
list3.add("c");
list3.add("d");

System.out.println("Elements of list:"+list);
System.out.println("Elements of list1:"+list1);
System.out.println("Elements of list2:"+list2);


//Method 1 which is used by many which gives the wrong result
for(int i=0;i<list.size();i++)
{
System.out.println("Size:"+list.size());
list.remove(i);

}
System.out.println("After deletion list elements are "+list);


//Method 2 which gives right output and simplified form of method 1
//don't use i<list1.size() in for loop otherwise there will be an     
                //ArrayIndexOutOfBoundException            
//because size of ArrayList will be decreased after deletion
//So it is advised to use a variable which stores the size of list and pass this variable to
                 // for loop
int length=list1.size();
for(int i=0;i<length;i++)
{
list1.remove(0);
}
System.out.println("After deletion list1 elements are "+list1);


//Method 3 using Iterator Class
Iterator<String> itr=list2.iterator();
while(itr.hasNext())
{
String element=itr.next();
itr.remove();
}
System.out.println("After deletion list2 elements are "+list2);

//Method 4 using foreach loop
//by using foreach loop we will get Exception i.e. ConcurrentModificaionException
//this is because for deleting elemens from arraylist
//we have to first use next() and then use remove() as done in method 3
//but in foreach loop compiler will first remove the element 
//and then call the next() function 
//so there will be this exception
for(String s:list3)
{
list3.remove(s);
}

System.out.println("After deletion list3 elements are "+list3);
}

}






Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Raw type of ArrayList And its Operations

 Unknown     23:17     Java     No comments   

import java.util.ArrayList;


public class RawArrayList {

public static void main(String[] args) {

ArrayList<Object> list=new ArrayList<Object>();
list.add(1);
list.add(2.0);
list.add("Hello");
list.add('a');
for(Object o:list)
{
System.out.println(o);
}
}

}



Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

User Defined Exception in Java

 Unknown     22:24     Java, Java Interview Questions     No comments   


public class ExceptionExOther {

public void methodA() throws UserDefinedException
{
try
{
System.out.println("Inside MethodA");
throw new UserDefinedException("Demo");
}
finally
{
System.out.println("MethodA's finally");
}
}

public static void main(String[] args) {

ExceptionExOther ex=new ExceptionExOther();
try {
ex.methodA();
} catch (UserDefinedException e) {
System.out.println("Caught "+e);
}
}

}



User Defined Exception


public class UserDefinedException extends Exception {

private String string;
public UserDefinedException(String str)
{
string=str;
}
public String toString()
{
return "UserDefinedException "+string;
}
}







Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Exception Handling in Java

 Unknown     22:09     Java, Java Interview Questions     No comments   


public class ExceptionEx {

public void methodA()
{
try
{
System.out.println("Inside MethodA");
return;
}
finally
{
System.out.println("MethodA's finally");

}
}
public void methodB()
{
try
{
System.out.println("Inside MethodB");
throw new RuntimeException("Demo");
}
finally
{
System.out.println("MethodB's finally");
}

}
public static void main(String[] args) {

ExceptionEx exc=new ExceptionEx();
try
{
exc.methodB();
}catch(Exception e)
{
System.out.println("Exception"+ e);
}
exc.methodA();
}

}





Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Best Java Interview Questions

 Unknown     10:45     Java, Java Interview Questions     No comments   

In this post i will explain how to convert an array of Strings to a list(i.e. ArrayList) by using two programs.
In first program I have converted the array to list by using List interface which is converting the array to ArrayList.

Arrays.asList(arr)

For converting Array to List we have used Arrays class which is situated in java.util.Arrays.And then we have used a asList Method which takes as argument the array and converts this array to ArrayList which is present in Arrays class i.e. java.util.Arrays.ArrayList. Here ArrayList is private static class inside Arrays.And by using this we are getting the list which is of fixed length.

So by applying any method of List we will get an Error in the program which is given below.



import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class ArrToList {

public static void main(String[] args) {
String[] arr={"Hello","Hi"};
List<String> list=Arrays.asList(arr);
System.out.println("After converting Array of string to list elements are: "+list);
list.add("My");
list.add("Name is Abhishek");
list.add("Awasthi");
System.out.println("After adding the contents to list elements are: "+list);

}

}







To get rid of this type of error we can pass this ArrayList which we have got from statement
                                                             Arrays.asList(arr);
to the constructor of ArrayList which is from java.util.ArrayList as
                               List<String> list=new ArrayList<String>(Arrays.asList(arr));
So that all the operations of List Interface can be used.



import java.util.*;


public class ArrayToList {

public static void main(String[] args) {

String[] arr={"Hello","Hi"};
List<String> list=new ArrayList<String>(Arrays.asList(arr));
System.out.println("After converting Array of string to list elements are: "+list);
list.add("My");
list.add("Name is Abhishek");
list.add("Awasthi");
System.out.println("After adding the contents to list elements are: "+list);

}

}




If you have any problem Please do comment.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Saturday, 11 October 2014

ek muskaan: सोलह श्रृंगार से सजूँगी आज मै

 Kavita house     10:11     Kavita Sangrah     No comments   

ek muskaan: सोलह श्रृंगार से सजूँगी आज मै: सोलह श्रृंगार से सजूँगी आज मै माथे पे चमकीली बिंदी और मांग में कुमकुम भरूँगी  इंतज़ार पल पल करूंगी निर्मोही चन्दा का  आज अपने पिया के बाहो...
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

ek muskaan: हमे तुमसे हुआ है प्यार हम क्या करे आप ही बताओ हम ...

 Kavita house     10:10     Kavita Sangrah     No comments   

ek muskaan: हमे तुमसे हुआ है प्यार हम क्या करे आप ही बताओ हम ...: आज एहसास हो रहा है की कितना प्यार है और कितना दर्द होता है बिछड़ने में लेकिन कुछ पल बहुत ख़ास होते है जो विशेष रूप से एहसास कराते है आज आंख...
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

ek muskaan: आज दिल बेचैन है तुम बिन

 Kavita house     10:08     Kavita Sangrah     No comments   

ek muskaan: आज दिल बेचैन है तुम बिन: आज दिल बेचैन है तुम बिन  आज के दिन भी जो दूर हु तुमसे मै ये सात समंदर कई दीवारों की तरह है  जिन्हें तोडना आज मेरे बस में नही है  मन भारी ...
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

ek muskaan: ये जान चली जाएगी तुम बिन

 Kavita house     10:07     Kavita Sangrah     No comments   

ek muskaan: ये जान चली जाएगी तुम बिन: तुम्ही हो राधा तुम्ही हो मीरा  तुम्ही हो दिन मेरा तुम्ही सवेरा  हर लम्हा मेरा बीत रहा तुम बिन  तुम ही हो मेरे विरह की पीड़ा  वृन्दावन  क...
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

ek muskaan: एहसासों की चिलमन भी क्या कमाल होती है

 Kavita house     00:26     Kavita Sangrah     No comments   

ek muskaan: एहसासों की चिलमन भी क्या कमाल होती है: एहसासों की चिलमन भी क्या कमाल होती है  जो हमारे दिल से जाने कितने बवाल करती है  इसके लिए मन में रोज कोहराम मचता है  इस मुहब्बत की वजह से ...
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

ek muskaan: अब मन पे नशा छाने लगा है

 Kavita house     00:25     Kavita Sangrah     No comments   

ek muskaan: अब मन पे नशा छाने लगा है: अब मन पे नशा छाने लगा है खुली आँखों से कोई अपना बनाने लगा है चद्दर से ढकने की बहुत कोशिश की मैंने फिर भी मेरे बाजू में आके वो मुझको सताने...
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

ek muskaan: हमे तुझसे कितनी मुहब्बत है ये हम जानते नही है मगर...

 Kavita house     00:23     Kavita Sangrah     No comments   

ek muskaan: हमे तुझसे कितनी मुहब्बत है ये हम जानते नही है मगर...: हमे तुझसे कितनी मुहब्बत है  ये हम जानते नही है मगर लेकिन तुझकोअपने  हर लम्हों में तलाश करते रहते है  जब सामने आते तो घबरा जाते है हम कुछ ...
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

ek muskaan: सहारे आदमी को कमजोर बना देते है

 Kavita house     00:22     Kavita Sangrah     No comments   

ek muskaan: सहारे आदमी को कमजोर बना देते है: सहारे आदमी को कमजोर बना देते है  और वक़्त के मुसाफिर उसे बैसाखियों पर बिठा देते है  फिर चलना तो हम चाहते है कुछ कदम मगर  वो हर पल हर कदम प...
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Friday, 10 October 2014

बिखरा ख्वाब

 Kavita house     12:42     Kavita Sangrah     No comments   

रेत की जमी पर इक मकान हमने भी बनाया था 
अपने यादो के खूबसूरत लम्हों से उसको सजाया था 
बड़ी ताकीद की थी उनको उसमे लाने की 
कई तन्हा राते गुजारी थी बिन चंदा संग अँधेरी रातो में 
पल पल हर पल इक इक लम्हा मैंने संजोया था 
अपने प्यार के हर इक पल को प्यार की मोतियों संग पिरोया था
ना ही खबर थी हमे नाही मालूम था
की ढह जायेगा ये रेत का महल जिसपे हमने आसिया बनाया था
की ढह जायेगा ये रेत का महल जिसपे हमने आसिया बनाया था
पल हम खेलते थे पल में झूमते थे अपने ख्वाबो के संग
कभी वो मेरी बाहों में होंगे इस झरोखे के पास
कभी आंखमिचौली खेलेंगे उस दरवज्जे के पीछे हम
कभी चुपके से आवाज दे के हम बुलाएँगे
तो कभी कभी अपनी ही यादो में खो जायेंगे
फिर कानो में धीरे से आवाज एक आएगी
हम उनको वो हमको और हम एक दूजे में खो जायेंगे
लेकिन ये क्या आँख खुली नींद टूटी
हाय ये क्या मेरी किस्मत मुझसे रूठी
बिन पानी के मेरी क्यों लुटिया डूबी
बिन पानी के मेरी क्यों लुटिया डूबी

खूबसूरत वो ख्वाबो का गुलिस्ता हमने सजाया था
रेत की जमी पर इक मकान हमने भी बनाया था
अपने यादो के खूबसूरत लम्हों से उसको सजाया था
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

tujhme fnaa hoon

 Kavita house     12:22     Kavita Sangrah     No comments   

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

 Kavita house     12:21     Kavita Sangrah     No comments   

कुछ हौसले टूट रहे है उनकी निगाहों को देख कर 
कुछ ख्व्वाब मेरे टूट गये सिसकती आँखों को देखकर 
कुछ हम टूट से गये वो कापती बाहों को देखकर 
की दर्द दिया किसने मेरे मांझी को लूटकर 
मेरा रोम रोम कांप गया उनके बारे में सोचकर 
की कुछ पल को दूर जाऊ
ंगा तो हो जायेगा ऐसे
की छुट जाएँगी मेरी साँसे मुझसे ही यु रूठकर
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

 Kavita house     12:20     Kavita Sangrah     No comments   

तोड़ कर दिल वो चले गये एक खिलौना समझकर हम तो राह तकते रहे दीवानों की तरहाकी इक बार देखेंगे मुझे पलट कर वो की जिन्दगी गुजार लेंगे तेरे इंतज़ार में हम

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

ये कैसा अभिशाप है

 Kavita house     12:16     Kavita Sangrah     No comments   

ये कैसा अभिशाप है मैंने क्या पाप किया है क्या आज के जीवन में गरीबी अभिशाप है मै कल भी पूछता था और आज भी पूछता हु और सायद कल भी यही सवाल होगाकी क्या गरीब होना पाप है दासता तो हमे वरदान में मिली है जिन्दगी बस और बस इसी चूल्हे चौके में बीती है सपने भी देखने का हक़ नही है हमे और हम खुशियों के मोहताज है बस हर लम्हा धीरे धीरे निकल रहा है कभी तपती दोपहर में तो कभी चुभती है सर्द हवाएपल तब भी नही कटतापल अब नही कटता कभी तो इस मजबूरी से थोड़ी दूरी हो जाए मगरलगता है इससे भी बचपन का साथ है दो वक़्त की रोटी के लिए हम कैसे तरसते है तो कुछ लोग मखमली रोटियों को रोड पर फेकते है इक आह सी निकलती है ये सब देखकर ये भी जाने कैसा एहसास है ये कैसा अभिशाप है ये कैसा अभिशाप है


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

मै पत्थर हु

 Kavita house     12:13     Kavita Sangrah     No comments   

मै राह में पड़ा रहा कई सदियों से कितने आये कितने चले गये किसी ने ठोकर मारी मुझको तो किसी ने रस्ते से ही हटा दिया किसीको ठोकर लगी मुझसे तो कोई ठोकर मार कर चला गया लेकिन मै था तन्हा तन्हा और हर पल अकेला ही चलता गया लोग कहते है बहुत ही हीन भावना से की मै पत्थर हु हाँ मै पत्थर हु तो मेरी खता है क्या इसमें किसी ने मारा मुझे किसी ने हटा दिया मै तो बस इधर से उधर उधर से इधर लुढकता रहा किसी को कुछ हुआ किसी ने कुछ किया तो मेरी संज्ञा दे दी गयी की वो पत्थर दिल है लेकिन क्या मुझको दर्द नही होता मुझे भी अकेलेपन का एहसास होता है मुझे भी तन्हाइया तन्हा रातो में डराती है मेरा भी मन होता है की मेरा कोई अपना हो मै भी जिसका सपना बनू किन्तु ये समाज संवेदनहीन हो गया मुझ पत्थर में तो जान आ गयी लेकिन ये जिन्दगी वाले कब पत्थर बन गये इसका संज्ञान इनको ही नही चलो देखता हु कब तक दर्द सहता हु कब तक तन्हा तडपता हु कब तक लोग तड़पाते है मै पत्थर नही हु ये बताना है कुछ करके दिखाना है श्री राम का इन्तजार कब तक करू मै मै इंसान बन गया पत्थर से और ये जीते जागते पत्थर बन गये ये बताना है
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Sunday, 5 October 2014

Equals and hashCode method in Java

 Unknown     10:48     Java     No comments   

package collections;

public class Employee1  {

String designation;
String dob;
int employeeId;
String name;
float salary;
public String getDesignation() {
return designation;
}
public void setDesignation(String designation) {
this.designation = designation;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public float getSalary() {
return salary;
}
public void setSalary(float salary) {
this.salary = salary;
}
public String toString()
{
return name+"\n"+salary+"\n"+employeeId+"\n"+dob+"\n"+designation;
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + employeeId;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Employee1 other = (Employee1) obj;
if (employeeId != other.employeeId)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}




}



package collections;

import java.util.*;

public class EmployeeManagement3  {

public void addEmployees(int numEmp,HashSet<Employee1> emp)
{

Scanner sc=new Scanner(System.in);
for(int i=1;i<=numEmp;i++)
{
Employee1 empl=new Employee1();
System.out.println("Enter Employee Name: ");
String name=sc.next();
empl.setName(name);
System.out.println("Enter Employee ID: ");
int id=sc.nextInt();
empl.setEmployeeId(id);
System.out.println("Enter Employee Designation: ");
String des=sc.next();
empl.setDesignation(des);
System.out.println("Enter Employee DOB: ");
String dt=sc.next();
empl.setDob(dt);
System.out.println("Enter Employee Salary: ");
float sal=sc.nextFloat();
empl.setSalary(sal);
emp.add(empl);

}
}
public void displayEmployees(HashSet<Employee1> empList)
{
//There are many methods by which we can retrieve the data but i am showing 2 methods

//Displaying Employee details using For each loop
/*for(Employee1 e:empList)
{
System.out.println(e);
}*/
//Display Employee details using Iterator
Iterator itr=empList.iterator();
while(itr.hasNext())
{
System.out.println(itr.next());
}
}
public boolean isEmployeePresent(String empName,HashSet<Employee1> emp)
{
boolean exists=false;
for(Employee1 e:emp)
{
if(e.getName().equals(empName))
{
exists=true;
break;
}
}
return exists;
}
public boolean deleteEmployee(String empName,HashSet<Employee1> emp)
{
boolean exists=false;
for(Employee1 e:emp)
{
if(e.getName().equals(empName))
{
exists=true;
emp.remove(e);
break;
}
}
return exists;
}

public static void main(String[] args) {
HashSet<Employee1> al=new HashSet<Employee1>();
EmployeeManagement3 em=new EmployeeManagement3();
System.out.println("Enter the number of employees: ");
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
em.addEmployees(num,al);
em.displayEmployees(al);
System.out.println("Enter the employee you want to remove: ");
String empName1=sc.next();
boolean bool=em.deleteEmployee(empName1, al);
System.out.println("Is the Employee Present and deleted? "+bool);
System.out.println("After deletion :");
em.displayEmployees(al);
System.out.println("Enter the employee you want to search: ");
String empName=sc.next();
bool=em.isEmployeePresent(empName, al);
System.out.println("Is the Employee Present? "+bool);


}


}






Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Collection Examples in Java

 Unknown     09:10     Java     No comments   

package come;

public abstract class Connection implements Comparable<Connection> {

private int connectionId;
private int customerId;
private double balance;
public Connection(int connectionId,int customerId,double balance)
{
this.connectionId=connectionId;
this.customerId=customerId;
this.balance=balance;
}
abstract double recharge(double bal);
abstract double deduct(double bal);
public int getConnectionId() {
return connectionId;
}
public int getCustomerId() {
return customerId;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public String toString()
{
return connectionId+" "+customerId+" "+balance;
}
public int compareTo(Connection o) {

int code = 0;
if(o.getConnectionId()< connectionId)
{
code = 1;
}
else if(o.getConnectionId()> connectionId)
{
code = -1;
}
return code;
}
}





package come;
import java.util.*;

public class Inventory {

ArrayList<Connection> connections;
Inventory()
{
connections=new ArrayList<Connection>();
}
boolean addConnection(Connection con)
{
boolean exist=true;
for(Connection c:connections)
{
if(c.getConnectionId()==con.getConnectionId())
{
exist=false;
break;
}
}
if(exist==true)
{
connections.add(con);
}
return exist;
}
double recharge(int conId,double recAmount)
{
double total=-1;
for(Connection con:connections)
{
if(con.getConnectionId()==conId)
{
total=con.getBalance();
total=total+recAmount;
//con.recharge(recAmount);
break;
}
}
return total;
}
double deduct(int conId,double dedAmount) throws ConnectionLockedException
{
double total=-1;
for(Connection con:connections)
{
if(con.getConnectionId()==conId)
{
if(con.getBalance()<0)
{
throw new ConnectionLockedException(con.getBalance());
}
else
{
total=con.getBalance();
total=total-dedAmount;
}
}
}
return total;
}
Set<Integer> getUniqueCustomerIDs()
{
Set<Integer> set=new HashSet<Integer>();
for(Connection con:connections)
{
set.add(con.getConnectionId());
}
return set;
}
HashMap<Integer,Connection> getConnectionHashMap()
{
HashMap<Integer,Connection> hMap=new HashMap<Integer,Connection>();
for(Connection con:connections)
{
hMap.put(con.getConnectionId(), con);
}
return hMap;
}
}



package come;

public class ConnectionLockedException extends Exception {

double currentBalance;
ConnectionLockedException(double currentBalance)
{
this.currentBalance=currentBalance;
}
public String getMessage()
{
return currentBalance+" is invalid balance";
}
}



package come;

import java.util.TreeSet;

public class NewInventory {

TreeSet<Connection>  conTree=null;
public NewInventory()
{
conTree=new TreeSet<>();
}
TreeSet<Connection> getConnections()
{
return conTree;
}
int addConnection(Connection con)
{
conTree.add(con);
return conTree.size();
}
}



package com;

public class Hobby {

String hobbyDescription;
String hobbyName;
public String getHobbyDescription() {
return hobbyDescription;
}
public void setHobbyDescription(String hobbyDescription) {
this.hobbyDescription = hobbyDescription;
}
public String getHobbyName() {
return hobbyName;
}
public void setHobbyName(String hobbyName) {
this.hobbyName = hobbyName;
}
public String toString()
{
return hobbyDescription+hobbyName;
}
}




package come;

public class ConnectionDemo {

public static void main(String[] args) {
Inventory inv=new Inventory();
Prepaid con1=new Prepaid(1,1,100);
Prepaid con2=new Prepaid(2,2,-122);
Prepaid con3=new Prepaid(3,3,300);
System.out.println(inv.addConnection(con1));
System.out.println(inv.addConnection(con2));
System.out.println(inv.addConnection(con3));
System.out.println("Recharge "+inv.recharge(1, 122));
try
{
System.out.println("Deduct1 "+inv.deduct(1, 500));
System.out.println("Deduct "+inv.deduct(2, 1220));
}catch(ConnectionLockedException ce)
{
ce.getMessage();
}
System.out.println("Unique Customer IDs "+inv.getUniqueCustomerIDs());
System.out.println("Hash Map "+inv.getConnectionHashMap().toString());
Prepaid con4=new Prepaid(3,3,300);
System.out.println(inv.addConnection(con4));
NewInventory ni=new NewInventory();
System.out.println("Tree "+ni.addConnection(con1));
System.out.println("Tree "+ni.addConnection(con2));
System.out.println("Tree "+ni.addConnection(con3));
System.out.println("Tree "+ni.addConnection(con4));
System.out.println("Tree output "+ni.getConnections());
}

}




Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

Ad


Jobsmag.inIndian Education BlogThingsGuide

Subscribe

Do you want fresh and hot updates about us? Then subscribe to our Feeds.

Total Pageviews

Popular Posts

  • Write a program in PL/SQL to print the factorial of a number.
    In this post I will explain how to get the factorial of any given number. For that first you need to know what is the procedure to find ...
  • To find the GCD of two numbers in PROLOG.
    gcd(X,Y):-X=Y,write('GCD of two numbers is '),write(X); X=0,write('GCD of two numbers is '),write(Y); Y=0,write('G...
  • Write a PL/SQL code to get the Fibonacci Sequence
    First, I will explain what is Fibonacci Sequence and how to get this series. So, Fibonacci Sequence is a series of numbers 0,1,1,2,3,5,8,1...

Label

All Articles Best Resources Blogging Boost Traffic Bootstrap C Plus Plus Collection Comedy Comedy Posts Comedy Videos Concurrency creative commons website Education Employee Entertainment Fibonacci Sequence free images GirlFriend Hinglish Cafe How To Image Websites Inspirational Java Java Interview Questions Java Networking Kavita Sangrah Life Lock Sreen Love Number System Patterns Perl Picture PL/SQL Plastic Engineering Programming Prolog public domain SEO Servlet Short Story Shortcut Keys Social Media Social Services SQL SuVichar Thread Traffic True Events Ultimate Guide Windows Tricks Windows8.1 WordPress

Blog Archive

  • ►  2020 (43)
    • ►  September (41)
    • ►  August (2)
  • ►  2019 (1)
    • ►  July (1)
  • ►  2018 (9)
    • ►  September (7)
    • ►  July (1)
    • ►  May (1)
  • ►  2017 (8)
    • ►  June (3)
    • ►  May (3)
    • ►  March (1)
    • ►  January (1)
  • ►  2016 (2)
    • ►  September (1)
    • ►  January (1)
  • ►  2015 (91)
    • ►  December (1)
    • ►  November (1)
    • ►  October (6)
    • ►  May (10)
    • ►  March (20)
    • ►  February (50)
    • ►  January (3)
  • ▼  2014 (339)
    • ▼  December (1)
      • The Leader
    • ►  October (55)
      • ServletContext in Servlet
      • sendRedirect() method in Servlet
      • Servlets in Java
      • HashMap in Java
      • HashSet In Java
      • Different ways to delete elements from ArrayList
      • Raw type of ArrayList And its Operations
      • User Defined Exception in Java
      • Exception Handling in Java
      • Best Java Interview Questions
      • ek muskaan: सोलह श्रृंगार से सजूँगी आज मै
      • ek muskaan: हमे तुमसे हुआ है प्यार हम क्या करे आप...
      • ek muskaan: आज दिल बेचैन है तुम बिन
      • ek muskaan: ये जान चली जाएगी तुम बिन
      • ek muskaan: एहसासों की चिलमन भी क्या कमाल होती है
      • ek muskaan: अब मन पे नशा छाने लगा है
      • ek muskaan: हमे तुझसे कितनी मुहब्बत है ये हम जानत...
      • ek muskaan: सहारे आदमी को कमजोर बना देते है
      • बिखरा ख्वाब
      • tujhme fnaa hoon
      • कुछ हौसले टूट रहे है उनकी निगाहों को देख कर कुछ...
      • तोड़ कर दिल वो चले गये एक खिलौना समझकर हम तो रा...
      • ये कैसा अभिशाप है
      • मै पत्थर हु
      • Equals and hashCode method in Java
      • Collection Examples in Java
    • ►  September (58)
    • ►  August (94)
    • ►  July (64)
    • ►  June (67)
  • ►  2013 (34)
    • ►  August (5)
    • ►  April (29)
  • ►  2012 (20)
    • ►  November (1)
    • ►  October (15)
    • ►  September (4)

Author

  • Earthcare Foundation NGO
  • Kavita house
  • Unknown
  • Unknown

Info

Copyright © Hub Of Geekz | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates