Converting an array to a List type
Object[] array = new Object[]{"12","23","34"};
java.util.List list = Arrays.asList(array);
Object can be a String array or Integer array. However, they cannot be a primitive array.
To convert a primitive array such as int to a List, the int array must be converted to an Object array such as Integer array.
Converting a List to an array.
List list = new ArrayList();
list.add("AB");
list.add("CD");
list.add("EF");
String[] sl = (String[]) list.toArray(new String[list.size()]);
To find the minimum in a integer array,
int min = (int) Collections.min(Arrays.asList(lenArr));
where lenArr is an Object[] array such as an Integer array.
To find the minimum in a integer array,
int max = (int) Collections.max(Arrays.asList(lenArr));
Wednesday, December 29, 2010
Wednesday, November 10, 2010
Setting JVM Size in Eclipse
One quick way to resolve the Java OutOfMemory error in Eclipse...
1) Open 'Debug Configurations' in Eclipse. (Run --> Debug Configurations)
2) In the left pane, click on 'Java Application'.
3) The list of java application ( with the main() method) are listed here.
4) Select the required Java Application.
5) In the right pane, click on the '(x)=Arguments'. Under VM Arguments, type
-Xmx1g - This will increase the heap size to 1 GB
-Xmx256m - This will increase the heap size to 256 MB.
6) Click Apply and Ok.
1) Open 'Debug Configurations' in Eclipse. (Run --> Debug Configurations)
2) In the left pane, click on 'Java Application'.
3) The list of java application ( with the main() method) are listed here.
4) Select the required Java Application.
5) In the right pane, click on the '(x)=Arguments'. Under VM Arguments, type
-Xmx1g - This will increase the heap size to 1 GB
-Xmx256m - This will increase the heap size to 256 MB.
6) Click Apply and Ok.
Wednesday, September 15, 2010
DB2 Basic Commands
1) To import data from a csv file to a table in database:
import from C:\testfile.csv of del insert into workemployee
2) To export data to a csv file from a table in database:
export to C:\names.csv of del select * from names
3) To connect to db2 database
connect to database_name user user_id using pwd
4) To set the schema for accessing the tables under a schema
set current schema schema_name
5) To list all tables under the schema or in general to list all tables. Two ways of doing the same.
- list tables for schema schema_name
- list tables
import from C:\testfile.csv of del insert into workemployee
2) To export data to a csv file from a table in database:
export to C:\names.csv of del select * from names
3) To connect to db2 database
connect to database_name user user_id using pwd
4) To set the schema for accessing the tables under a schema
set current schema schema_name
5) To list all tables under the schema or in general to list all tables. Two ways of doing the same.
- list tables for schema schema_name
- list tables
Sunday, May 30, 2010
Javascript Tips - 2
To trim a word using Javascript, use the following:
var field1 = document.formname.textbox.value.replace(/^\s+\s+$/g, "");
var field1 = document.formname.textbox.value.replace(/^\s+\s+$/g, "");
Deployment in JBoss
Following are the steps to deploy a war file in JBoss.
1) First, create a HTML page - form.html or a JSP file.
2) Have a folder say, CoffeeV1. Have a folder inside CoffeeV1 with the name WEB-INF. Place the form.html file or JSP inside CoffeeV1.
3) Create a folder under WEB-INF called classes.
4) Create deployment descriptor(web.xml) file with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<display-name>Hello Coffee</display-name>
</web-app>
5) Place the web.xml file inside WEB-INF.
6) Run the following commands to create a war file.
D:\HFSApps>cd CoffeeV1
D:\HFSApps\CoffeeV1>set CLASSPATH=C:\j2sdk1.4.2_02\bin
D:\HFSApps\CoffeeV1>set JAVA_HOME=C:\j2sdk1.4.2_02
D:\HFSApps\CoffeeV1>"%JAVA_HOME%\bin\jar.exe" -cvf CoffeeV1.war *.html WEB-INF
D:\HFSApps\CoffeeV1>copy CoffeeV1.war C:\jboss\server\default\deploy\
7) Start the JBoss server using run.bat command.
8) In web browser, enter http://localhost:8080/CoffeeV1/form.html.
1) First, create a HTML page - form.html or a JSP file.
2) Have a folder say, CoffeeV1. Have a folder inside CoffeeV1 with the name WEB-INF. Place the form.html file or JSP inside CoffeeV1.
3) Create a folder under WEB-INF called classes.
4) Create deployment descriptor(web.xml) file with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<display-name>Hello Coffee</display-name>
</web-app>
5) Place the web.xml file inside WEB-INF.
6) Run the following commands to create a war file.
D:\HFSApps>cd CoffeeV1
D:\HFSApps\CoffeeV1>set CLASSPATH=C:\j2sdk1.4.2_02\bin
D:\HFSApps\CoffeeV1>set JAVA_HOME=C:\j2sdk1.4.2_02
D:\HFSApps\CoffeeV1>"%JAVA_HOME%\bin\jar.exe" -cvf CoffeeV1.war *.html WEB-INF
D:\HFSApps\CoffeeV1>copy CoffeeV1.war C:\jboss\server\default\deploy\
7) Start the JBoss server using run.bat command.
8) In web browser, enter http://localhost:8080/CoffeeV1/form.html.
Subscribe to:
Comments (Atom)