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

World News

Entertainment

Terminate Java Virtual Machine (JVM) Example

/*
Terminate Java Virtual Machine (JVM) Example
This Java example shows how to terminate currently running
Java Virtual Machine(JVM) using halt method of Runtime class.

*/

public class TerminateVirtualMachine {

public static void main(String args[])
{
/*
* get current Java Runtime using getRuntime()
* method of Runtime class.
*/
Runtime runtime = Runtime.getRuntime();

/*
* To forcibly terminate the currently running virtual machine, use
*
* void halt(int status)
* method of Runtime class.
*
* Usually, non-zero status is passed as status for abnormal exit.
*
* Please note that, unlike exit method, this method DOES NOT invoke
* shutdown hooks or run object finalizers.
*
*
*/

System.out.println("About to halt the current jvm");
runtime.halt(1);

/*
* THIS METHOD NEVER RETURNS NORMALLY.
* This statement will never executed, as the JVM is
* terminated!
*/
System.out.println("JVM Terminated");
}

}

/*
Typical output would be
About to halt the current jvm
*/
Continue Reading | comments

Get Free Memory of Java Virtual Machine(JVM) Example

/*
Get Free Memory of Java Virtual Machine(JVM) Example
This Java example shows how to get amount of free memory
in the Java Virtual Machine(JVM) using freeMemory method
of Java Runtime class.
*/
public class GetFreeMemory {

public static void main(String args[])
{
/*
* get current Java Runtime using getRuntime()
* method of Runtime class.
*/
Runtime runtime = Runtime.getRuntime();

/*
* To determine amount of free memory available to current
* Java Virtual Machine(JVM), use
*
* long freeMemory()
* method of Runtime class.
*/

long freeMemory = runtime.freeMemory();

System.out.println(freeMemory + " bytes free in JVM");
}


}

/*
Typical output would be
4993048 bytes free in JVM
*/
Continue Reading | comments

Get Available Processors using Java Runtime Example

/*
Get Available Processors using Java Runtime Example
This Java example shows how to get number of processors
available to current Java Virtual Machine (JVM).
*/
public class GetAvailableProcessors {

public static void main(String args[])
{
/*
* get current Java Runtime using getRuntime()
* method of Runtime class.
*/
Runtime runtime = Runtime.getRuntime();

/*
* use availableProcessors method to determine
* how many processors are available to the Java Virtual
* Machine (JVM).
*/

int numberOfProcessors = runtime.availableProcessors();

System.out.println(numberOfProcessors + " processor available to JVM");
}
}

/*
Typical output of this program would be,
1 processor available to JVM
*/
Continue Reading | comments

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
 
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