Posts

Kill a Process

Unix > ps -ef | grep java > kill -9 PID Windows > netstat -ano | findstr 8100 TCP    0.0.0.0:8100           0.0.0.0:0              LISTENING       8732 TCP    [::]:8100              [::]:0                 LISTENING       8732 > taskkill /PID 8732 /F  SUCCESS: The process with PID 8732 has been terminated.

Search only Folders in Windows 7

Image
GUI search : To restrict by file type Use Example ------------------------ --- ------- Folders folders kind:folders Folder name foldername foldername:mydocs Command line search: dir java /ad /s /b

Message driven beans(MDB) and transaction attributes

"Message-driven beans may declare only the NOT_SUPPORTED or REQUIRED transaction attribute. The other transaction attributes don't make sense in message-driven beans because they apply to client-initiated transactions." Why ? MDB are called asynchronously. Therefore NEVER, SUPPORTS, REQUIRES_NEW transaction attributes are not make sense, because there isn't pre-existing transaction context for MDB. NEVER throws Exception if there is pre-existing transaction context, but that don't ever occur. If there is pre-existing transaction context, SUPPORTS will run in that transaction context. (But, there is NO such in MDB!) REQUIRES_NEW always run in new transaction context, but this behavior is always the same to REQUIRED. REQUIRED Vs. REQUIRES_NEW why are we allowed to use a REQUIRED , but not a REQUIRES_NEW? When we specify theh RequiresNew, it comes with an implicit understanding that if the client has a transaction, it needs to be suspended. i.e. the existence of a cl...

What is serialVersionUID?

If a class implements Serializable interface, your IDE worn you to add serialVersionUID or it add automatically. This variable holds a private static final long and IDE automatically declared it to 1L. class SerializeMe implements Serializable { private static final long serialVersionUID = 1L; private String data; public SerializeMe (String data) { this.data = data; } public String getData() { return data; } } Field data represents some information stored in the class. Note that serialVersionUID is a static value, then it should not have been serialized. But why is this so impotent? public class SerialVersionUIDTester { public static void main(String [] args) throws Exception { File file = new File("out.ser"); FileOutputStream fos = new FileOutputStream(file); ObjectOutputStream oos = new ObjectOutputStream(fos); SerializeMe serializeMe = new SerializeMe("serialVersionUID is 1L"); ...

-- Start Telnet feature in Vista --

-> Open the Start Bar and search Telnet. -> If it does not show anything in Programs do the following. -> Open Control Panel. -> Click on Programs. -> Click on Programs and Features. -> Under that click "Turn Windows features on or off" (left side of the window). -> Click Continue on the Pop-Up. -> A Dialog box will show up and it might take a while to populate the list. -> Go down in Dialog box and look under Tablet PC Optional Components. -> It will say Telnet Client. -> Check the box -> then OK. It may take a while. -> check the telnet in command prompt.

-- Are you a Android Developer? --

If you going to develop an application using Android (specially hardware dependent application, just like new protocol for WI-FI or new network application), curren- tly you must have a mobile phone which is fully support Android OS. There was a Nokia phone and one Motorola phone which is support to Android partially. Because some Android features doesn't work will on those phones. That implies only T-Mobile G1 is the solution to such development. Android announce that they are going to issue a phone, for Android developments and they are call it as a Android Dev Phone 1 . Android Dev Phone 1 is a SIM-unlocked and hardware-unlocked device that is designed for advanced developers. The device ships with a system image that is fully compatible with Android 1.0, so you can rely on it when developing your applications. We can use any SIM in the device and can flash custom Android builds that will work with the unlocked bootloader. The device currently costs $399 (USD) (including free sh...

-- Google Android --

What is Android? Android is a software stack + Operating system and middle-ware, for mobile devices. Its provides a SDK for develop a applications on Android using Java language. Now it has a Eclipse plug-in for Android application development. Why is this so cool Android is a full open-source platform for mobile devices. It has a full access to hardware level and free to develop software. Features * Application framework enabling reuse and replacement of components * Dalvik virtual machine optimized for mobile devices * Integrated browser based on the open source WebKit engine * Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional) * SQLite for structured data storage * Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF) * GSM Telephony (hardware dependent) * Bluetooth, EDGE, 3G, and WiFi (hardware dependent...

-- What is ICEfaces --

CEfaces is a framework, which can be used to create high user interactive web pages. In another words this technology enables to develop and deploy thin-client, REA - Rich Enterprise Application in pure Java. Pure Java means... NO JavaScript. Therefore do not need any kind of knowledge about JavaScript. So JEE application development skills can directly apply to these technology. The other thing is thin-client... Thin client means, there are no Applets or proprietary browser plug-ins required to run ICEfaces. And Rich web application environment enables to... smooth, Incremental page updates... that do not require a full page refresh (i.e. need only partial refresh) to view the changes in the application. Only elements, which are changed, need to updated during the render phase. And also using ICEfaces, we can develop rapid applications, even within 2/3 months; single developer can develop a fully featured web application. Because these applications are easy to maintains, ustomize and ...

-- Read a Property File --

--------------------- ERA.properties -------------------- webapp.name=ERA Admin DashBoard webapp.version=Version: neo_jsf_ice_with_tree_06 author.name=Jayasanka Illangarathne author.url=http://jayasanka.blogspot.com company.name=Virtusa Private Ltd: company.url=http://www.virtusa.com copyright.year=2008 dataBase.name=EraDB server.path=jdbc:sqlserver://localhost:1433 dataBase.uname=sa dataBase.passwd=jayasanka -------------------------java file------------------- package com.resource; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Properties; public class ERAProperties { public static void main(String[] args) { Properties properties = new Properties(); try { // load the resource file properties.load(new FileInputStream("src/com/resource/ERA.properties")); // get a property String name = properties.getProperty("author.name"); System.out.println...

-- Spring Framework --

Image
-> backGround - Spring is an open-source framework, created by Rod Johnson and described in his book Expert One-on-One: J2EE Design and Development. - Spring is a lightweight inversion of control and aspect-oriented container framework. -> Spring is a development style like J2EE EJB.But solve some limitations of EJB -> problem: in EJB, has to write several classes to make a component. such as the home interface,the local interface,and the bean itself. in addition has to create a deployment descriptor for the bean. -> solution: incorporates XDoclet XDoclet is a code generation tool that can generate all of the necessary EJB files from a single source file. -> Problem: when testing, have to fire up the container in each test and each change of the code. It is a waisting time, the development lifecycle will add a "waitting" phase. (code -> wait -> test). ...

-- Send Mails --

To implement the mail function u must download the javaMail.jar file, and include it to ur lib folder. package com.neo.mail; import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class AdminMail { public void postMail( String recipients[ ], String subject, String message , String from) throws MessagingException { boolean debug = false; //Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", "mailsvr"); // create some properties and get the default Session Session session = Session.getDefaultInstance(props, null); session.setDebug(debug); // create a message Message msg = new MimeMessage(session); // set the from and to address InternetAddress addressFrom = new InternetAddress(from); msg.setFrom(addressFrom); InternetAddress[] addressTo = new InternetAddress[recipients.length]; for (int i = 0;...

-- How to Schedule a Task --

In some application some tasks need to be run periodically for example GUI screen should update the data from server periodically. This java tips illustrate a method of scheduling a task periodically. Developers may use it for repetitive invoking of a method as per their requirements. For this aim, first you have to make a class extending TimerTask abstract class and write code in run method, you want to run repetitively. import java.util.TimerTask; public class Shedule extends TimerTask{ public void run() { // add the task here } } In your main program you can call this code to schedule task: java.util.Timer timer = new java.util.Timer(); Calendar date = Calendar.getInstance(); date.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); date.set(Calendar.HOUR, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); //sheduler run now //timer.schedule(new Shedule(), 0, 60 * 60); // Schedule to run every Sun...

-- Encode a URL --

import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; public final class TestURLEncode{ public static void main( String[] args ) throws URISyntaxException, MalformedURLException{ // reserved chars that are not escaped in URLs include: // ; / ? : @ & = + $ , URI uri = new URI( "http", "//www.example.com/you & I 10%? weird & weirder neé", null ); System.out.println( uri.toURL().toString() ); // prints http://www.example.com/you%20&%20I%2010%25?%20wierd%20&%20wierder%20neé // note how it fails to encode é } }

-- Velosity Templates --

Velosity Engine: -> Velocity is an open source templating tool developed by an international volunteer community and hosted by the Apache Software Foundation's Jakarta Project -> It's free and the source code is available under the Apache Software License, a business-friendly open source license -> language - Velocity Template Language (VTL). -> any Aplication using Velosity requires -> 1.0 Template -> 2.0 Corresponding java programme -------------template------------------------ Hello $name! Welcome to Velosity! -------------java programme------------------ import java.io.StringWriter; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; public class HelloWorld{ PSVM throws Exception{ VelocityEngine ve=new VelocityEngine(); ve.init(); Template t=ve.getTemplate("src/com/neo/..../myvelocity/helloworld.vm"); VelocityContex...

How to Connect DataBase to Java Application -JDBC

import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class db { public static void main(String[] args){ try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc: mydb "); Statement stmt = conn.createStatement(); ResultSet results = stmt.executeQuery("SELECT * FROM student "); while(results.next()){ System.out.println(results.getString("SName")); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } }

What is Thin client ---in J2EE

In J2EE thin client is a client who do not query databases, execute large functions just like JSP, heavy part of the system will execute using Servlet

Aspect-Oriented Programming

What is AOP ????? Aspect-Oriented Programming (AOP) complements OO programming by allowing the developer to dynamically modify the static OO model to create a system that can grow to meet new requirements. …. Just as objects in the real world can change their states during their lifecycles, an application can adopt new characteristics as it develops. Using an AOP language (such as AspectJ) or libraries (such as Spring), programmers can code this functionality once and then define where to weave it into existing Ex: public class First{ public void method(String s){ Logger.sign_in(); // Business logic ---> AAA Logger.sign_out(); } } public class Second{ public void function(Object o){ Logger.sign_in(); // Business logic ---> BBB Logger.sign_out(); } } Here we can see that logging functi...

Enable Sinhala in ur computer....

For windows users.. Get and install sinhala pack form fonts.lk You can download it by click in here. use instruction come with setup (this is based on Wijayasekara Unicode).