DirectorySoftwareBlog Details for "Free Code,Example Code"

Free Code,Example Code

Free Code,Example Code
The FreeCode FreeCode blog is the largest collection of free Internet related source code. Free programs are available in the following languages, Java, Javascript, Ajax and Perl...
Articles: 1, 2

Articles

How to access a database by ADO with JavaScript
2008-05-12 17:34:00
I have not found any sample that shows database access with javaScript. Well, I created one. It is very simple since Javascript has the activeXObject that allow us to call an external object in the same way that vbscript uses CreateObject. //************************************** // Name: ADO With JavaScript // Description:I have not found any sample that shows database access with javaScript.
More About: Database , Access
Encrypts a string by the given "key"
2008-05-12 16:57:00
A more slightly advanced encryption.Encrypts a string by the given "key". import javax.swing.JOptionPane; public class betterencryptor { public static void main(String [] args) { int key1 = Integer.parseInt(JOptionPane.showInputDia log("Input a key, a random large *prime* number:")); String message1 = JOptionPane.showInputDialog("Input a string to be encrypted/decrypted:"); String crypt1
How to create a zip file
2008-03-12 10:34:00
This code example shows how to create a zip file. What we do is to create an input stream from the file we want to compress, and while we read from it we write the contents to an output stream. This output stream is of type ZipOutputStream which takes an File OutputStream as parameter. Next we have to add a zip entry to the output stream before we start writing to it. We will also clean up by
More About: Create
Write to file using BufferedOutputStream
2008-02-21 15:29:00
This code snippet shows how to write to a file using a BufferedOuputStream. Now it should be said that if you want to write text to a file you should probably find it easier to go with a Write r class like the BufferedWriter instead. The write method of the BufferedOuputStream takes either a byte array or an int as argument so that is why we have to call getBytes() on any String that we provide to
More About: File
Read from file with BufferedInputStream
2008-02-21 15:28:00
This example shows how to read the contents of a file using a BufferedInputStream. There are a couple of ways to do so, and in this example we use a byte array to store the data read. We loop through the file contents and fill out buffer up to the size of the buffer array until there are no more data left to read. It possible to read from the file one byte at a time, but to use a buffer is more
More About: File , Read
Read each line in a comma separated file into an array
2008-02-21 15:14:00
In this example we read the lines of a comma separated file and split the values into an array. This is done fairly easy with the split() method, which takes a separator as an argument and returns an array of Strings. import java.io.BufferedRead er; import java.io.File Reader; import java.io.FileNotFoundException; import java.io.IOException; public class CsvTest { public void readFile() {
More About: Line , Array , Separated
Base64 encoding and Base64 decoding in C
2008-02-19 14:57:00
#include "lib.h" /** * characters used for Base64 encoding */ const char *BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn opqrstuvwxyz0123456789+/"; /** * encode three bytes using base64 (RFC 3548) * * @param triple three bytes that should be encoded * @param result buffer of four characters where the result is stored */ void _base64_encode_triple(unsigned char triple[3],
How to quickly sort Vector of objects that implement the Comparable interfa
2008-02-19 14:35:00
import java.util.Vector ; /** * Implements the quicksort algorithm. * Sort s Vectors of objects that implement the Comparable interface. * The sort is based on Comparable.compare(obj) method. * @see Comparable */ public class QuickSorter { /** * performs the sort. * * @param vect the Comparable Objects to be sorted. */ public static void sort(Vector vect) {
Listing the system properties
2008-02-18 16:01:00
By listing the properties of the system you run the program on you can find out a lot about it. Your program maybe should act in a certain way depending on what operating system it's currently on. This code example shows how to retrieve the properties and how to enumerate through and print them out to the console. import java.util.Enumeration; import java.util.Properties ; /** * * @author
More About: System , Listing
Check if a String is a valid date
2008-02-18 15:57:00
This example checks if a String is a valid date by parsing the String with an instance of the SimpleDateFormat class and returns true or false. import java.text.SimpleDateFormat; import java.text.ParseException; public class DateTest { public boolean isValidDate(String inDate) { if (inDate == null) return false; //set the format to use as a constructor argument
More About: Check
how to determine window size in javascript
2008-02-18 15:37:00
Use this snippet to determine the size of an open window. Can be used in many different situations, e.g., for setting the size of a div. if (window.innerWidth) theWidth=window.innerWidth; else if (document.documentElement && document.documentElement.clientWidth) theWidth=document.documentElement.clientW idth; else if (document.body) theWidth=
More About: Javascript , Size , Window
Getting data from the computer clipboard
2008-02-17 16:16:00
Getting data from the system clipboard is implemented nicely in Java through the Toolkit class which has a getSystemClipboard method. Since there isn't necessarily text contents in the clipboard the getSystemClipboard returns an instance of the class Transferable. With that instance we have to test if the content is text before we do any processing with it. To test the code, just copy some text
More About: Computer , Data
Placing text on the computer clipboard
2008-02-17 16:15:00
It is very easy to place text on the clipboard with Java. We just get an instance of the default toolkit and from that we get hold of a reference to the clipboard object. To place some text on the clipboard we need to pass an object of type Transferable and another object which is the clipboard owner to the method setContents. To make it easy we may specify null as the owner, and as the first
More About: Computer , Text , Clipboard
Connect to a database and read from table
2008-02-17 16:10:00
This example shows how to connect to a database, in this case a MS SQL Server database and read rows from a table. It is assumed that the table has 3 columns and they all contains string-values (datatype char, varchar etc.). To connect to another database type, just change the driver and url to match the specific type. Note that you'll have to change some of the values to match your own
More About: Read , Database , Table , Connect
How to extract contents of a zip file
2008-02-17 15:57:00
This example shows how to extract a zipfile containing one file (or entry). The name of the zip file is 'compressed.zip' and we want to write the contents to a file called 'extracted.txt'. We start by opening an input stream to the compressed file and an output stream to the file where we want the content to be extracted. After that we get the next entry of the zip file (and the only entry in
More About: File , Contents , Extract
How to list the contents of a zip file
2008-02-17 15:55:00
To list the contents of a zip file you need to get the entries of the file since every file in a zip file is represented by an entry. In this case we assume that the filename of the zip file is 'testfile.zip'. By calling the entries method of the ZipFile object we get an Enumeration back that can be used to loop through the entries of the file. Note that we have to cast each element in the
More About: List , Contents
How to remove duplicate items from an ArrayList
2008-02-15 07:55:00
This code example shows how to remove duplicate items from an ArrayList. ArrayList arrayList1 = new ArrayList(); arrayList1.add("A"); arrayList1.add("A"); arrayList1.add("B"); arrayList1.add("B"); arrayList1.add("B"); arrayList1.add("C"); //Create a HashSet which allows no duplicates HashSet hashSet = new HashSet(arrayList1); //Assign the HashSet to a new
More About: Items
How to send a POST Request with Parameters From a Java Class
2008-02-15 07:52:00
his example shows how to sent a POST request to a server with attached parameters. Two parameters are sent in the example code below, width and height. We use the URL and URLConnection classes to open the connection to the destination. Then the output stream is retrieved by calling getOutputStream() on the URLConnection object. With the output stream we can write the parameters and then start
More About: Java , Post , Request , Send , Class
how to remove a line from a text file
2008-02-15 07:46:00
This example shows how to delete a line from a file. The method removeLine FromFile takes two parameters, the first parameter is the file to remove from and the second parameter is the content of the line to remove. A tempfile is created and written to, except for the content that matches the second parameter. This way very large files can be handled without demanding so much internal memory. The
More About: Text
MIDlet examples to invoke a servlet
2007-07-07 16:21:00
import java.io.*; import javax.microedition.io.*; import javax.microedition.lcdui.*; import javax.microedition.midlet.*; /** * An example MIDlet to invoke a servlet. */ public class InvokeServletMidlet1 extends MIDlet { private Display display; String url = "http://127.0.0.1:8080/examples/servlet/H elloServlet"; public InvokeServletMidlet1() { display = Display.getDisplay(
More About: Examples , Xamp
Socket MIDlet example code(J2ME)
2007-07-07 16:19:00
package ora.ch6; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import javax.microedition.io.Connector; import javax.microedition.io.StreamConnection; import javax.microedition.lcdui.Alert; import javax.microedition.lcdui.AlertType; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import
More About: Code , Socket , Xamp
Http MIDlet example code(J2ME)
2007-07-07 16:16:00
Really working examples categorized by API, package, class. You can compile and run our examples right away! Not from source code for Java projects - only working examples! Copy, compile and run! package ora.ch6; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import javax.microedition.io.Connector; import javax.microedition.io.Http Connection; import
More About: Code , Xamp
Implementing a Class That Can Be Sorted
2007-06-27 16:58:00
In order for a class to be used in a sorted collection such as a SortedTree or for it to be sortable by Collections.sort(), the class must implement Comparable. public class MyClass implements Comparable { public int compareTo(Object o) { // If this o, return a positive value } }
Implementing String trimming (Ltrim and Rtrim) in C
2007-06-22 11:54:00
Here is a simple implementation of implementing a simple Left trim (ltrim) and Right trim(rtim) of unwanted characters from a C style string. (null terminated strings). Doesn't suffer the overheads of the memmove implementation in which the worst case scenario (a string containing all junk characters) is approx. N^2 / 2. #include char* rtrim(char* string, char junk); char* ltrim(char* string,
More About: String , G String , Ming , Trim , Tring
URLEncoder for J2ME
2007-06-17 07:33:00
J2ME tech: how to encode url in J2ME programing? Example code: URLEncoder .encode(str,"UTF-8")); URLEncoder class for J2ME: package com.mobile.util; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; /** * Adapted from J2SE java.net.URLEncoder. */ public class URLEncoder { public static String
More About: Coder
javascript remove attribute method
2007-06-13 11:59:00
removeAttribute() Syntax, Parameters and Note Removes the specified attribute value from the element. Returns true (successful) or false (failed). Syntax: document.getElementById("elementID").remo veAttribute(param1, param2) document.all.elementID.removeAttribute(pa ram1, param2) // IE only Parameters: param1 Required; the name of the attribute. param2 Optional; the type
More About: Javascript , Bute , Tribute , Tribu , Method
javascript create attribute method
2007-06-13 11:45:00
createAttribute() Syntax, Parameters and Note Create s an attribute node. It also works with user-defined XML elements, allowing for the creation of custom attributes. Syntax: document.createAttribute(param1) Parameters: param1 Required; the name of the attribute. createAttribute() example code function function1() { var
More About: Javascript , Bute , Tribute , Tribu
A HashMap object in Javascript like the HashMap in Java
2007-06-11 15:15:00
The following Map Object code is an implementation of a HashMap in java for javascript. function Map() { // members this.keyArray = new Array(); // Keys this.valArray = new Array(); // Values // methods this.put = put; this.get = get; this.size = size; this.clear = clear; this.keySet = keySet; this.valSet = valSet; this.showMe = showMe; //
More About: Java , Javascript , Like
A block of text to use as input to the regular expression matcher
2007-06-04 12:12:00
// : c12:TheReplacements.java // From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002 // www.BruceEckel.com. See copyright notice in CopyRight.txt. import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import
More About: Text , Regular , Xpress , Block , Regular Expression
How to catch TAB key press with JavaScript in Firefox,Safari,Opare & IE
2007-06-01 11:25:00
The example code is tested in IE, Firefox and Opare. Probably also works in Netscape as well as others like Safari . var obj; var TAB = 9; function catchTAB(evt,elem) { obj = elem; var keyCode; if ("which" in evt) {// NN4 & FF & Opera keyCode=evt.which; } else if ("keyCode" in evt) {// Safari & IE4+ keyCode=evt.keyCode; }
More About: Press , Javascript , Catch
More articles from this author:
1, 2
40580 blogs in the directory.
Statistics resets every week.


Contact | About
© Blog Toplist 2008 - SEO by FeWorks
eXTReMe Tracker