Compile and Run java file from Notepad++

Just like to share old trick , used to compile and run java file
using notepad++.

To cook recipe: To compile and run java file using Notepadd++.

Ingredients:
Notepad++ Application
Installed JDK on system

Environment:
Windows

Procedure:

1> Make sure java path is properly set in windows environment variable.
To check go to command prompt and test java and javac commands working.

2>In notepad++, open any simple java file to test.

3>Press F5. Paste following in input box.
cmd /k cd $(CURRENT_DIRECTORY) && javac -cp . $(FILE_NAME)

3>Click save. Give Commad name say "Compile Java ".
Select shortcut combination. say Ctrl+Alt+2

4>Click Ok.Click Run to compile java file.

5>Now in Notepad++ again press F5. Paste following in input box.
cmd /k cd $(CURRENT_DIRECTORY) && java -cp . $(NAME_PART)

6>Click save. Give Command name say "Run Java File".

Select shortcut combination. say Ctrl+Alt+1

7>Click Ok. Click Run to run java file.

8>Now try with shortcut combinations. Shortcut will not work if it isn`t unique.


Advertisements

String Reaplce All Method with Ignore case

The core String class does not provide replace all method with ignore case.

I have written a method replaceAllIgnoreCase().This method take three parameter as:

 /**
 * @param original: Original string to be modified. Must not be null.
 * @param regex: String to be discarded.
 * @param replacement: String to be replaced with.
 * @return
 */

This is ready to use method copy class to your project and call method as:

<p style="text-align: center;"><code>
.
.
.
String result=EString.replaceAllIgnoreCase(org,regex,replacement);
.
.
.

Here is source code:

/**
*
* @author abhishek.anne@gmail.com
* @publish @ playjava.wordpress.com
*
*/
public class EString {

public static void main(String[] args) {
String test = "SUN Rise and sun Set.";
String result = replaceAllIgnoreCase(test, "SUN", "Moon");
System.out.println("Original String :" + test);
System.out.println("Result String :" + result);
}

/**
* @param original: Original string to be modified. Must not be null.
* @param regex: String to be discarded.
* @param replacement: String to be replaced with.
* @return
*/
static String replaceAllIgnoreCase(String original, String regex,
String replacement) {
String r = null;

int repl = replacement.length();
int regl = regex.length();
int dif = repl - regl;
int cnt = 0;
String regLc = regex.toLowerCase();
String repLC = replacement.toLowerCase();
String buf = original.toLowerCase();
int index;
while ((index = buf.indexOf(regLc)) &gt;= 0) {
buf = buf.substring(index + regl);
if (r != null) {
if (dif == 0) {
r += original.substring(r.length() + dif, r.length()
+ dif + index);
r += replacement;
} else {
r += original.substring(r.length() - (dif * cnt),
r.length() - (dif * cnt) + index);
r += replacement;
cnt++;
}
} else {
if (index != 0) {
r = original.substring(0, index) + replacement;
cnt++;
} else {
r = replacement;
cnt++;

}
}
}
if(dif==0)
{
r += original.substring(r.length() + dif, original.length());
}
else
{
r += original.substring(r.length() - (dif * cnt),original.length());

}
return r;
}
}

Share your experience and any bug or performance issue if detected.

One other option is provided as:

String sentence = "The sly brown Fox jumped over the lazy foX.";
String result = sentence.replaceAll("(?i)fox", "dog");
System.out.println("Input: " + sentence);
System.out.println("Output: " + result);

But this was not working all the time for me.