Username:   Password:  

test

	import java.io.FileOutputStream;
	import java.io.IOException;
	import java.io.InputStream;
	import java.io.OutputStream;
 
	public class Test
	{
		public static void main (String args[]) throws IOException
		{
			String from = "D:/src/test.jpg";
			String to = "D:/dest/test.jpg";
			copy(from, to);
		}
		public static void copy (String from, String to) throws IOException
		{
			InputStream in = null;
			OutputStream out = null;
			System.out.println(System.currentTimeMillis())
			{
				try
				{
					InputStream inFile = new FileInputStream (from);
					in = new BufferedInputStream (inFile);
					OutputStream out = new FileOutputStream (to);
					out = new BufferedOutputstream (outFile);
					while (true)
					{
						int data = in.read();
						if (data == -1)
						{
							break;
						}
						out.write(data);
					}
					System.out.println(System.currentTimeMillis());
				}
				finally
				{
					if (in != null)
					{
						in.close();
					}
					if (out != null)
					{
						out.close();
					}
				}
			}
		}

test

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
 
public class Test
{
	public static void main (String args[]) throws IOException
	{
		String from = "D:/src/test.jpg";
		String to = "D:/dest/test.jpg";
		copy(from, to);
	}
	public static void copy (String from, String to) throws IOException
	{
		InputStream in = null;
		OutputStream out = null;
		System.out.println(System.currentTimeMillis())
		{
			try
			{
				in = new FileInputStream(from);
				out = new FileOutputStream(to);
				while(true)
				{
					int data = in.read();
					if (data == -1)
					{
						break;
					}
					out.write(data)
				}
				System.out.println(System.currentTimeMillis())
			}
			finally
			{
				if (in != null)
				{
					in.close();
				}
				if (out != null)
				{
					out.close();
				}
			}
		}
	}

test

int iSize = strTest.size();
for (int iIndex = 0; iIndex < iSize; iIndex++)

test

int iSize = strTest.size();
for (int iIndex = 0; iIndex < iSize; iIndex++

tset

for (int iIndex = 0; iIndex < strTest.size(); iIndex++)

test

public class TestVarAccess1
{
	private int instanceVariable;
	private static int staticVariable;
 
	void localVarAccess(int val)
	{
		int localVariable = 0;
		for (int i = 0; i < val; i++)
		{
			localVariable += i;
		}
	}
	void staticVarAccess(int val)
	{
		int localVar = staticVariable;
		for (int i = 0; i < val; i++)
		{
			localVar += i;
		}
		staticVariable = localVar;
	}
	void instanceVarAccess(int val)
	{
		int localVarbl = instaceVariable;
		for (int i = 0; i < val; i++)
		{
			localVarbl += i;
		}
		instanceVariable = localVarbl;
	}
}

test

package config.java;
public class TestVarAccess
{
	private int instanceVariable;
	private static int staticVariable;
 
	void localVarAccess(int val)
	{
		int localVariable = 0;
		for (int i = 0; i < val; i++)
		{
			localVariable += i;
		}
	}
	void staticVarAccess(int val)
	{
		for (int i = 0; i < val; i++)
		{
			staticVariable += i;
		}
	}
	void instanceVarAccess(int val)
	{
		for (int i = 0; i < val; i++)
		{
			instanceVariable += i;
		}
	}
}

test

package config.java;
 
public class TestVarAccess
{
	private int instanceVariable;
	private static int staticVariable;
 
	void localVarAccess(int val)
	{
		int localVariable = 0;
		for (int i = 0; i < val; i++)
		{
			localVariable += i;
		}
	}
	void staticVarAccess(int val)
	{
		for (int i = 0; i < val; i++)
		{
			staticVariable += i;
		}
	}
	void instanceVarAccess(int val)
	{
		for (int i = 0; i < val; i++)
		{
			instanceVariable += i;
		}
	}
}

tset

package config.java;
 
import java.io.FileInputStream;
import java.io.FileNotFoundException;
 
public class Test
{
	String strFileName = "D:/test/test.jpg";
	public static FileInputStream fi (String strFileName)
		throws FileNotFoundException
		{
			FileInputStream fis = new FileInputStream (strFileName)
			System.out.println("fi:FileInputStream created");
			return fis;
		}
}

tesyt

public static boolean Mytest2(Requisituin req)
{
	if (req instanceof Requisition)
	{
		return false;
	}
	else
	{
		return true;
	}
}

test

public static exception EXCEPTIONREUSE = new Exception();
 
//Much Faster
 
try
{
	throw EXCEPTIONREUSE;
}
catch (Exception e)
{
	...
}
 
//Much Slower
 
try
{
	throw new Exception;
}
catch (Exception e)
{
	....
}

test

package config.java;
 
public class Test
{
	public String ReqLineNumber()
	{
		return new StringBuffer.append("This").append("is").append("a class").
		append(Requisition.ClassName).toString();
	}
}

test

package config.java;
 
public class Test
{
	public String ReqLineNumber()
	{
		return "This" + "is" + "a test" + Requisition.ClassName;
	}
}

test

package config.java;
 
public class Test
{
	public String ReqLineNumber()
	{
		return "This" + "is" + "a test";
	}
}

test

package config.java;
import java.io.IOException;
import ariba.util.log.Log;
public class Requisition
{
	public static final String ClassName = "Requisition";
	public static void main(String args[]) throws IOException
	{
		Requisition[] requisition = new Requisition[100];
		for (int iIndex = 0; iIndex < 100; iIndex++)
		{
			requisition[iIndex] = new Requisition();
			Log.customer.debug("%s :: This is a test class",ClassName);
		}
	}
}

test

package config.java;
import java.io.IOException;
public class Test
{
	public static void main(String args[]) throws IOException
	{
		StringBuffer buffer = new StringBuffer();
		for (int iIndex = 0; iIndex < 100; iIndex++)
		{
			buffer.append("test");
		}
	}
}

trest

test

package config.java;
import java.io.IOException;
public class Test
{
	public static void main(String args[]) throws IOException
	{
		for (int iIndex = 0; iIndex < 100; iIndex++)
		{
			StringBuffer buffer = new StringBuffer();
			buffer.append("test");
		}
	}
}

test

Tags

test

Example of MySQL connection in Java

#
#   mysql-connector-java-3.0.11-stable-bin.jar or later must be downloaded
#   from:http://dev.mysql.com/downloads/connector/j/3.0.html
#
#   Compile:
#     javac Connect.java
#
#   Run:
#     java Connect
 
import java.sql.*;
 
public class Connect
{
	public static void main (String[ ] args)
	{
	Connection conn = null;
	String url = "jdbc:mysql://localhost/";
	String userName = "root";
	String password = "";
 
	try
	{
		Class.forName ("com.mysql.jdbc.Driver").newInstance ( );
		conn = DriverManager.getConnection (url, userName, password);
		System.out.println ("Connected");
	}
	catch (Exception e)
	{
		System.err.println ("Cannot connect to server");
	}
	finally
	{
		if (conn != null)
		{
			try
			{
				conn.close ( );
				System.out.println ("Disconnected");
			}
			catch (Exception e) { /* ignore close errors */ }
		}
	}
}

Shows how to connecto to a MySQL database with Java.

Tags

Java MySQL