<div style='background-color: none transparent;'></div>

World News

Entertainment

Example of keySet method of HashMap.

HashMapKeySet.java

package net.roseindia.java;

import java.util.HashMap;

import java.util.Set;

public class HashMapKeySet {

public static void main(String[] arr) {

/* Create object of HashMap */

HashMap obHashMap = new HashMap();

/* Strore value in HashMap */

obHashMap.put(new Integer(1), "AAA");

obHashMap.put(new Integer(2), "BBB");

obHashMap.put(new Integer(3), "CCC");

obHashMap.put(new Integer(4), "DDD");

obHashMap.put(new Integer(5), "EEE");

/* Create a set of keys of hashmap */

Set obKeySet = obHashMap.keySet();

System.out.println("Set of Keys : " + obKeySet); } }
Continue Reading | comments

Retrieving XML Data Using GWT

package com.google.gwt.sample.simplexml.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.xml.client.Document;
import com.google.gwt.xml.client.Element;
import com.google.gwt.xml.client.Node;
import com.google.gwt.xml.client.NodeList;
import com.google.gwt.xml.client.XMLParser;

public class SimpleXML implements EntryPoint {
private static final String XML_LABEL_STYLE = "xmlLabel";
private static final String USER_TABLE_LABEL_STYLE = "userTableLabel";
private static final String USER_TABLE_STYLE = "userTable";
private static final String NOTES_STYLE = "notes";

public void onModuleLoad() {
RequestBuilder requestBuilder = new
RequestBuilder(RequestBuilder.GET,"customerRecord.xml");
try {
requestBuilder.sendRequest(null, new RequestCallback() {
public void onError(Request request, Throwable exception) {
requestFailed(exception);
}
public void onResponseReceived(Request request, Response response){
renderXML(response.getText());
}
});
} catch (RequestException ex) {
requestFailed(ex);
}
}
private FlexTable createOrderTable(FlowPanel xmlParsed, String label){
HTML orderTableLabel = new HTML("

" + label);
xmlParsed.add(orderTableLabel);
FlexTable orderTable = new FlexTable();
orderTable.setStyleName(USER_TABLE_STYLE);
orderTable.setBorderWidth(3);
orderTable.getRowFormatter().setStyleName(0, USER_TABLE_LABEL_STYLE);
orderTable.setText(0, 0, "Employee ID");
orderTable.setText(0, 1, "Firstname");
orderTable.setText(0, 2, "Lastname");
orderTable.setText(0, 3, "City");
orderTable.setText(0, 4, "State");
orderTable.setText(0, 5, "Zip");
xmlParsed.add(orderTable);
return orderTable;
}
private void customerPane(String xmlText, FlowPanel xmlParsed) {
Document customerDom = XMLParser.parse(xmlText);
Element customerElement = customerDom.getDocumentElement();
XMLParser.removeWhitespace(customerElement);

String nameValue = getElementTextValue(customerElement, "name");
String title = "

" + nameValue + "

";
HTML titleHTML = new HTML(title);
xmlParsed.add(titleHTML);

String notesValue = getElementTextValue(customerElement, "notes");
Label notesText = new Label();
notesText.setStyleName(NOTES_STYLE);
notesText.setText(notesValue);
xmlParsed.add(notesText);

FlexTable pendingTable =
createOrderTable(xmlParsed, "Employee Details");
NodeList orders =
customerElement.getElementsByTagName("order");
int pendingRowPos = 0;
int completedRowPos = 0;
System.out.println(orders.getLength());
for (int i = 0; i < orders.getLength(); i++) {
Element order = (Element) orders.item(i);
HTMLTable table;
int rowPos;
if (order.getAttribute("status").equals("pending")) {
table = pendingTable;
rowPos = ++pendingRowPos;
} else {
table = pendingTable;
rowPos = ++pendingRowPos;
}
int columnPos = 0;
fillInOrderTableRow(customerElement, order, table, rowPos, columnPos);
}
}

private void fillInOrderTableRow
(Element customerElement, Element order,
HTMLTable table, int rowPos, int columnPos)
{
String orderId = order.getAttribute("id");
table.setText(rowPos, columnPos++, orderId);

Element item = (Element)
order.getElementsByTagName("item").item(0);
String itemUPC = item.getAttribute("Firstname");
String itemName = item.getFirstChild().getNodeValue();
Label itemLabel = new Label(itemUPC);
itemLabel.setTitle(itemName);
table.setWidget(rowPos, columnPos++, itemLabel);

String orderedOnValue = getElementTextValue
(customerElement, "Lastname");
table.setText(rowPos, columnPos++, orderedOnValue);

Element address = (Element)
order.getElementsByTagName("address").item(0);
XMLParser.removeWhitespace(address);
NodeList lst = address.getChildNodes();
for (int j = 0; j < lst.getLength(); j++) {
Element next = (Element) lst.item(j);
String addressPartText = next.getFirstChild().getNodeValue();
table.setText(rowPos, columnPos++, addressPartText);
}

}
private String getElementTextValue(Element parent, String elementTag){
return parent.getElementsByTagName(elementTag).item(0)
.getFirstChild().getNodeValue();
}
private void renderXML(String xmlText) {
final TabPanel tab = new TabPanel();
final FlowPanel xmlSource = new FlowPanel();
final FlowPanel xmlParsed = new FlowPanel();
tab.add(xmlParsed, "Employee");
tab.add(xmlSource, "XML");
tab.selectTab(0);
RootPanel.get().add(tab);
xmlPane(xmlText, xmlSource);
customerPane(xmlText, xmlParsed);
}

private void requestFailed(Throwable exception) {
Window.alert("Failed to send the message: "
+ exception.getMessage());
}
private void xmlPane(String xmlText, final FlowPanel xmlSource) {
xmlText = xmlText.replaceAll("<", "<");
xmlText = xmlText.replaceAll(">", ">");
Label xml = new HTML("
" + xmlText + "
", false);
xml.setStyleName(XML_LABEL_STYLE);
xmlSource.add(xml);
}
}
Step2:-Create a xml file named customerRecord.xml.

customerRecord.xml



Girish Tewari
Roseindia.net Rohini


Bronze Sword

Haldwani
Uttaranchal
263126

Tewari



Mahendra Singh Dhoni
Roseindia.net Rohini



Bronze Sword

Lucknow
UttarPradesh
263139

Tewari



Step3:-Create html file named SimpleXML.html





Simple XML Example




Retrieving XML Data Using GWT



Example of loading an XML file from the server.




Another way for running this example is to download this example, Extract it and put the extracted folder in the GWT directory. Place this extracted folder in the samples directory of the GWT toolkit. Just double click on the cmd SimpleXML-shell.cmd to view the output of the program.

Continue Reading | comments

sql php code



$host = "localhost";
$user = "root";
$password = "root";
$database = "komal";
$connection = mysql_connect($host,$user,$password)
or die("Could not connect: ".mysql_error());
mysql_select_db($database,$connection)
or die("Error in selecting the database:".mysql_error());
$array = array(1,2,3,4);
foreach ($array as $value){
$sql="Select * from stu where id =".$value;
$sql_result=mysql_query($sql,$connection)
or exit("Sql Error".mysql_error());
$sql_num=mysql_num_rows($sql_result);
echo "";
echo "";
echo "";
echo "";
while($sql_row=mysql_fetch_array($sql_result)) {
$id=$sql_row["id"];
$name=$sql_row["name"];
echo "";
echo "";
}
echo "
Id Name
".$id."".$name."

";
}
?>

Continue Reading | comments

Java read file line by line

import java.io.*;

public class ReadFile {
public static void main(String[] args) throws Exception {

File f = new File("C:/Hello.txt");
if (!f.exists() && f.length() < 0) {
System.out.println("The specified file does not exist");
} else {
FileReader fr = new FileReader(f);
BufferedReader reader = new BufferedReader(fr);
String st = "";
while ((st = reader.readLine()) != null) {
System.out.println(st);
}
}
}
}
Continue Reading | comments

Java write to file line by line

import java.io.*;

class FileWrite {
public static void writeToFile(String text) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(
"C:/new.txt"), true));
bw.write(text);
bw.newLine();
bw.close();
} catch (Exception e) {
}
}

public static void main(String[] args) throws Exception {
String st1 = "Hello";
String st2 = "Where there is will, there is a way";

writeToFile(st1);
writeToFile(st2);

System.out.println("File created successfully!");
}
}
Continue Reading | comments

Simple java program

Write a program that prints the following pattern:

*
***
*****
*******
*****
***
*


public class Print{
public static void main(String[] args){
int i=1;
int j;
while(i<=7){
for(j=1;j<=i;j++)
System.out.print("*");
i=i+2;
System.out.println();
}
i=5;
while(i>=1){
for(j=1;j<=i;j++)
System.out.print("*");
i=i-2;
System.out.println();
}
}
}
Continue Reading | comments

PHP displaying the time and date into your timezone


ECHO "Date using date()fucntion is:"."
";

echo date("M d Y H:i:s",mktime(0,0,0,1,1,1998))."
";

ECHO "Date using gmdate()fucntion is:"."
";

echo gmdate("M d Y H:i:s",mktime(0,0,0,1,1,1998))."
";

?>
Continue Reading | comments

ASCII Table

ASCII Table

session_start();
$table = "";
$table .= "
";
$table .= "";
$table .= "";
$table .= "";
$table .= "";

$table .= "";
for($count = 1; $count <= 256; $count++)
{
$table .= "";
$table .= "";
if($count % 8 == 0) $table .= "";
}
$table .= "";
$table .= "
";
$table .= "";
$table .= " A S C I I - T a b l e";
$table .= "
";
$table .= "
";
$table .= "";
$table .= "
";
$table .= $count;
$table .= "
";
$table .= chr($count);
$table .= "
";
?>


Geerson - Ascii table






Continue Reading | comments

Strings sample source codes

Trim Function

Left - ltrim() function

$text = "\t\tThese are a few words :) ... ";
$trimmed = ltrim($text);
// $trimmed = "These are a few words :) ... "
$trimmed = ltrim($text," \t.");
// $trimmed = "These are a few words :) ... "
$clean = ltrim($binary,"\0x00..\0x1F");
// trim the ASCII control characters at the beginning of $binary
// (from 0 to 31 inclusive)

?>

Right - rtrim() function

$text = "\t\tThese are a few words :) ... ";
$trimmed = rtrim($text);
// $trimmed = "\t\tThese are a few words :) ..."
$trimmed = rtrim($text," \t.");
// $trimmed = "\t\tThese are a few words :)"
$clean = rtrim($binary,"\0x00..\0x1F");
// trim the ASCII control characters at the end of $binary
// (from 0 to 31 inclusive)

?>
Continue Reading | comments

Parsing a Query String

Parsing a Query String

$str = "first=value&arr[]=foo bar&arr[]=baz";
parse_str($str);
echo $first; // value
echo $arr[0]; // foo bar
echo $arr[1]; // baz

parse_str($str, $output);
echo $output['first']; // value
echo $output['arr'][0]; // foo bar
echo $output['arr'][1]; // baz

?>
Continue Reading | comments

Calendar for any month any year

Calendar for any month any year


#
# *** Set time stamp.Check for month requested(value from request form)
# *** If no value has been set then make it for current month
#
if(!$year){$year=2000; }
if(!$req_month || $req_month=="none")
{
$dt_and_tm=time();
}
else
{
$dt_and_tm=mktime(0,0,0,$req_month,1,$year);
}
#
# *** Find out the month number from the time stamp we just created
# *** Find out the day of the week from the same(0 to 6 for Sunday to
# *** Saturday) add "1" so that it becomes 1 to 7
#

$month=date("n",$dt_and_tm);
$week_day=date("w",$dt_and_tm)+1;
#
# *** Set number days in requested month
#
if($month==1 || $month==3 || $month==5 || $month==7 || $month==8 || $month==10 ||
$month==12)
{
$no_of_days=31;
}
elseif($month==4 || $month==6 || $month==9 || $month==11)
{
$no_of_days=30;
}
#
# *** If the month requested is Feb. Check whether it is Leap Year
#
elseif($month==2)
{
if(date("L",$dt_and_tm))
{ $no_of_days=29 ;}
else
{$no_of_days=28;}
}
$month_full=date("F",$dt_and_tm);


#
# ******* HTML code goes from here
# ******* First row in HTML table displays month and year
# ******* Second row is allotted for week days
# ******* Table contains six more rows (total 42 table cells)
#
?>








#
# *** We need to start form week day and print total number of days

# *** in this month.For that we need to find out the last cell.
# *** While looping end current row and start new row for each 7 cells
#
$last_cell=$week_day+$no_of_days;
for($i=1;$i<=42;$i++)
{
if($i==$week_day){$day=1;}
if($i<$week_day || $i>=$last_cell)
{

echo "";
if($i%7==0){echo "\n";}
}
else
{

echo "";
$day++;
if($i%7==0) { echo "\n"; }

}
}
?>

$year" ; ?>
Sunface="Arial , Times New Roman " size=2 color="#ffffff">Monface="Arial , Times New Roman " size=2 color="#ffffff">Tueface="Arial , Times New Roman " size=2 color="#ffffff">Wedface="Arial , Times New Roman " size=2 color="#ffffff">Thuface="Arial , Times New Roman " size=2 color="#ffffff">FriSat
?
$day

Continue Reading | comments

Databases sample source codes

A couple of functions that convert an IP address into its color code
and not-color-code. Useful when viewing an apache log with a mysql result grouped by IP

/*this function converts $ipaddr into a color string*/
function IP2Color($ipaddr) {

$pieces=explode(".",$ipaddr);
$color="";

for($i=0;$i<3;$i++) {
if(($pieces[$i]>=0) && ($pieces[$i]<=255)) {
$color.=dechex($pieces[$i]);
}
}
$color=substr($color."000000",0,6);
return("#".strtoupper($color));
}

/*this function converts $ipaddr
to anti color string*/

function IP2NotColor($ipaddr) {

$pieces=explode(".",$ipaddr);
$color="";

for($i=0;$i<3;$i++) {
if(($pieces[$i]>=0) && ($pieces[$i]<=255)) {
$color.=dechex((128+$pieces[$i]) % 255);
}
}
$color=substr($color."000000",0,6);
return("#".strtoupper($color));
}

Example:

$IP=getenv("REMOTE_ADDR");
print "\n";
print " \n";
print "
color='".IP2NotColor($IP)."'>$IP
\n";
?>
Continue Reading | comments
 
Copyright © 2011. B.Sc B.Tech MCA Ploytechnic Mini,Main Projects | Free Main Projcets Download | MCA |B.tech . All Rights Reserved
Company Info | Contact Us | Privacy policy | Term of use | Widget | Advertise with Us | Site map
Template Modify by Creating Website. Inpire by Darkmatter Rockettheme Proudly powered by Blogger