Friday, March 26, 2010
Linear Search Java Example
import java.util.Scanner;
//##################################################
// Linear Search
//##################################################
//Program has list of integers saved in an array and
//program will take inputs from user and search that
//if that input is present in Array of Integers.
public class linearSearch {
public static void main(String args[]) {
int[] listOfIntegers = { 1, 34, 53, 23, 77, 98, 101, 20, 45, 66, 84 };
int inputTobeSearch;
Scanner sn = new Scanner(System.in);
inputTobeSearch = sn.nextInt();
int token = -1;
for (int i = 0; i < listOfIntegers.length; i++) {
if (listOfIntegers[i] == inputTobeSearch) {
token = i;
}
}
if (token != (-1)) {
System.out
.println("Input integer " + inputTobeSearch
+ " is present at " + (token + 1)
+ "th place in the Array");
} else
System.out.println("Input integer " + inputTobeSearch
+ " is not present in the Array");
}
}
Thursday, March 25, 2010
Execute a command from Java Program on Windows Mac or *nix System
So wrote a code and thought it will be nice to share, or may be it will be good for me, if I want to look at it after a while :)
The code below will run command from Java file even if it is Windows or Mac OS or Unix
//Package name is of the package
package finalgui;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
/**
*
* @author Vinit Patwa
*/
public class RunCommand {
private static String ls_str;
public static void main(String args[]) {
try {
Process ls_proc;
//we want to run command "mvn clean install"
//It is expected that "mvn" is in your PATH
String mvnClean = "mvn clean install";
//We are storing the OS on system in String OS
String OS = System.getProperty("os.name");
System.out.println("OS is: " + OS);
if (OS.contains("Windows")) {
ls_proc = Runtime.getRuntime().exec("cmd.exe /C mvn clean install");
} else {
ls_proc = Runtime.getRuntime().exec(mvnClean);
}
//We can also display the output of the command Here
DataInputStream ls_in = new DataInputStream(
ls_proc.getInputStream());
try {
BufferedReader br = new BufferedReader(new InputStreamReader(ls_in));
while ((ls_str = br.readLine()) != null) {
System.out.println(ls_str);
}
} catch (IOException e1) {
System.exit(0);
}
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
}
}
Friday, March 5, 2010
JBPM new web based BPMN editor

The jBPM Modeller is an advanced web based BPMN editor aimed at non technical business users. No software needs to be installed on the user's machine, a plain web browser is enough to get the job done. Business analysts can easiliy produce complex process models with the tool, which then later can be imported by developers in their Eclipse environment without any conversion needed.
The jBPM Modeller is based on the fantasic web based modeling tool by Signavio. In less than a minute, every stakeholder involved can view, edit and collaborate on process models through their own brower. source: www.jboss.org
Wednesday, March 3, 2010
java.io.IOException: CreateProcess: ... error=193
Runtime.getRuntime().exec("C:\\maven\\apache-maven-2.2.1\\bin\\mvn pax:provision");
I got following Exception -
java.io.IOException: Cannot run program "C:\maven\apache-maven-2.2.1\bin\mvn": CreateProcess error=193, %1 is not a valid Win32 application
To resolve this problem, the command should be invoked as:
Runtime.getRuntime().exec("cmd.exe /C C:\\maven\\apache-maven-2.2.1\\bin\\mvn pax:provision");
And it worked.
(Running executable from Java Jar file)
Tuesday, March 2, 2010
Install Maven Pax Plugin
The Pax Plugin is a "Swiss Army(tm) knife" for OSGi that provides goals to create, build, manage and deploy many types of OSGi bundles. While the easiest way to install and use this plugin is by using the Pax-Construct scripts, its goals can also be used directly on the Maven command line, or inside other Maven POMs.
Steps for installing Maven Pax Construct Plugin:
1. Get the pax zip and unzip it to temp (or any other directory you prefer):
http://repo1.maven.org/maven2/org/ops4j/pax/construct/scripts/1.4/scripts-1.4.zip
2. Open up the command prompt and enter the command:
set PATH=C:\temp\pax-construct-1.4\bin;%PATH%
Saturday, August 29, 2009
How to increase Netbeans IDE heapsize
It's always good to keep a copy of netbeans.conf file before starting this process.
- From the
etcdirectory in the NetBeans IDE installation directory, copy thenetbeans.conffile into your NetBeans IDE user directory, for example:$HOME/ .netbeans/caps/etcdirectory.Note - You may need to create the
etcdirectory in the NetBeans IDE user directory. - In your NetBeans IDE user directory, edit the
—J-Xmxcommand line Java startup switch in thenetbeans.conffile, for example:# command line switches
netbeans_default_options=" -J-Xms32m -J-Xmx128m -J-XX:PermSize=32m
-J-XX:MaxPermSize=96m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true" - Restart NetBeans IDE.