provide-free-support Ujjwal's Blog: j2ee
Showing posts with label j2ee. Show all posts
Showing posts with label j2ee. Show all posts

Monday, April 13, 2009

Comments in java

We all use comments to describe the Java code. There are three types if comments in Java as demonstrated in this Java tutorial by SUN:

// text

where the compiler ignores everything from // to the end of the line

/* text */

where the compiler ignores everything from /* to */ and

/** documentation */

which is ignored by the compiler the same way as the previous comment type. This one is a special comment as this indicates a documentation comment. The JDK javadoc tool uses doc comments when preparing automatically generated documentation.

I am not going to tell you how to use them. There are many articles and documentation written about that. We all know how to use them and most of us use them on a daily basis. Over time we can develop a stereotype. Mine looks like this:


/** first name */
private String firstName;

/** last name */
private String lastName;

/**
* Constructs and returns the full name
* @return full name
*/
public String getFullName() {
if (firstName == null) {
if (lastName == null) {
// user does not have a name specified
return "[no name]";
}
else {
return lastName;
}
}
else {
if (lastName == null) {
return firstName;
}
else {
// construct full name from first and last name
return firstName + " " + lastName;
}
}
}


As you can see, I use doc comments to describe the meaning and function of my class members. I also like to use line comments, rather than block comments. Even if my comment spans multiple lines I prefer to use // comments. It's due to my IDE settings. When I press Ctrl+/ it un-/comments the selected lines. It's very neat feature and I use it a lot.

Recently, I was doing some code modifications and I wanted to re-visit some code later. I decide to break the code by putting a comment in the middle if it, so it would not compile and I would be forced to come back to it.

I did somethig like this:


myObject.getAnother()/* change to ID */.getName();

To my surprise the code did not break. Even when I changed it to


myObject.getAnother()./* change to ID */getName();

Obviously, when I did this


myObject.getAnother().ge/* change to ID */tName();

the code broke. At the end I made it to break in a nice way, anyway


myObject.getAnother()./* change to ID */.getName();

Sunday, April 12, 2009

how to detect usb device connected to system using java code

Hi Friends,

Here's d code..

import java.io.*;

/**
* Waits for USB devices to be plugged in/unplugged and outputs a message
*
*
*@author Ujjwal Soni
*@version 1.0, 16/04/2009
*/
public class FindDrive
{
/**
* Application Entry Point
*/
public static void main(String[] args)
{
String[] letters = new String[]{ "A", "B", "C", "D", "E", "F", "G", "H", "I"};
File[] drives = new File[letters.length];
boolean[] isDrive = new boolean[letters.length];

// init the file objects and the initial drive state
for ( int i = 0; i < letters.length; ++i )
{
drives[i] = new File(letters[i]+":/");

isDrive[i] = drives[i].canRead();
}

System.out.println("FindDrive: waiting for devices...");

// loop indefinitely
while(true)
{
// check each drive
for ( int i = 0; i < letters.length; ++i )
{
boolean pluggedIn = drives[i].canRead();

// if the state has changed output a message
if ( pluggedIn != isDrive[i] )
{
if ( pluggedIn )
System.out.println("Drive "+letters[i]+" has been plugged in");
else
System.out.println("Drive "+letters[i]+" has been unplugged");

isDrive[i] = pluggedIn;
}
}

// wait before looping
try { Thread.sleep(100); }
catch (InterruptedException e) { /* do nothing */ }

}
}
}

Tuesday, October 14, 2008

Simple Defination for EJB Session Facade

Instead of accessing the ENINTY Bean directly, Â You access the client through Session bean, i.e you call session bean first which in turn call entity bean, this is called session facade

difference b/w EJB2.1 and EJB3.0

EJB3.0
  1. No need of Home Interface (EJBHome),but it is needed in EJB2.0
  2. No more confusions to make an EJB remote or local,it's the client which would decide and cast to appropriate.
  3. Just write SINGLE simple Java class and annotate it to be Stateless/Stateful/Entity/MessageDriven.Container
  4. No Deployment Descriptors , MetaData Annotations are explored which is introduced in J2SE5.0
  5. Forget all EJB life cycles.For example Entity bean life cycle in 3.0 is new,managed,detached,removed.
  6. Ejb 3.0 siplifies the developement of the application

    Ready to develop complex query,inner/outer join with EJB3.0.
The main difference lies in the persistence In case of EJB 3.0 there is JPA Java persistence API which makes the mapping of EntityBeans with the database easy with the help of a service called as EntityManager.

Mapping is done with the help of annotations unlike in EJB2.0.
Home interfaces are eliminated.
Deployment descriptors are an option in EJB 3.0.
EJB3.0 also supports webservice client through SOAP and WSDl.

Finally, concluding this topic I think the main difference is that EJB 3.0 is moved towards annotations based programming model and dependency injection to make our life easy . 



For more information please visit http://javaknowledgestorm.blogspot.com/2009/04/differences-between-ejb20-and-ejb30.html

Saturday, August 30, 2008

Java's way of decompiling a class file

Hi Friends,

I finsished up with my project work early today. So, i thought of writing to this blog. I found an inbuilt way of decompiling the java class file that contains the binary data. Yes, jdk provides an inbuilt command that is javap.

Using javap you can decompile the java file. Folks, many of us might be using 3rd party tools like cavaj to decompile the class file, but java has its own way of doing this. Below is the example on how to do this.

c:\> javap Ujjwal.class

Cheers!

Ujjwal Soni

Tuesday, August 19, 2008

Trick to make netbeans fast

Hi,

There is a file named 'netbeans.conf' which can be found in \etc\ which you can edit to increase the amount of memory that NetBeans runs with. Edit the property named 'netbeans_default_options'. Increasing the -Xms and -Xmx options will increase the amount of RAM avialable to the JVM that NetBeans will be running inside of.
Example:
netbeans_default_options="-J-Xms384m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=96m -J-Xverify:none"

This example will allow NetBeans to run with a minimum of 384 megabytes of RAM and a maximum of 512 megabytes of RAM.


Cheers!


Ujjwal B Soni

best-it-exam-    | for-our-work-    | hottst-on-sale-    | it-sale-    | tast-dumps-us-    | test-king-number-    | pass-do-it-    | just-do-it-    | pass-with-us-    | passresults-everything-    | passtutor-our-dumps-    | realtests-us-exam-    | latest-update-source-for-    | cbtnuggets-sale-exam    | experts-revised-exam    | certguide-sale-exam    | test4-sale-exam    | get-well-prepared-    | certkiller-sale-exam    | buy-discount-dumps    | how-to-get-prepared-for-the    | in-an-easy-way    | brain-dumps-sale    | with-pass-exam-guarantee    | accurate-study-material    | at-first-try    | 100%-successful-rate    | get-certification-easily    | material-provider-exam    | real-exam-practice    | with-pass-score-guarantee    | certification-material-provider    | for-certification-professionals    | get-your-certification-successfully    | 100%-Pass-Rate    | in-pdf-file    | practice-exam-for    | it-study-guides    | study-material-sku    | study-guide-pdf    | prep-guide-demo    | certification-material-id    | actual-tests-demo    | brain-demos-test    | best-pdf-download    | our-certification-material    | best-practice-test    | leading-provider-on    | this-course-is-about    | the-most-reliable    | high-pass-rate-of    | high-pass-rate-demo    | recenty-updated-key    | only-for-students-free-download    | courseware-plus-kit-for    | accurate-answers-of    | the-most-reliable-id    | provide-training-for    | welcome-to-buy    | material-for-success-pass    | provide-free-support    | best-book-for-pass    | accuracy-of-the-answers    | pass-guarantee-id    | pass-exam-key    | pass-sku-id    | study-for-exid    | pdf-sku-exid    | sku-pdf-id    | pdf-demo-key    | exam-demo-ske    | pass-it-dump    |
http://www.menuiserie-dauvergne.com/    | http://www.menuiserie-dauvergne.com/    |