Sunday, December 9, 2012

Java enterprise edition

J2EE Its really VAST.
I cant say while updating this blog, how many new components being adding to the J2EE stuff or how many component's version number changing in upward or downward.. Really it is saying by the geeks that we are in the changing world. Really technology changing in fast pace. But if we simply say, this list for j2ee is huge still growing never shrinking.. You have to update yourself in the newest technologies to stay in this stardom. Naming few here in the following list. By clicking on the individual item you can get a birds-eye-view of the related technology.

  • JAVA
  • JSP
  • Servlet
  • JSF
  • Struts
  • Hibernate
  • EJB
  • JMS
  • JDBC
In addition to this a J2ee developer have to be well versed in the technologies related fundas design pattern, XML, Application/web servers and many many more. I think everybody scared of being in to the java technology by seeing this list. Instead of they being into .net or database and many more.
Share your thoughts

Java HelloWorld program explained

We can step into the world of java by this simple program

  1. class JavaDemo{


  2. public static void main(String Args[])


  3. {


  4. System.out.println("HelloWorld!");


  5. }


  6. }


  • Line1: Every java program starts with class keyword and followed by user defined class names
  • Line2:
    * public: The method can be accessed outside the class / package
    * static: You need not have an instance of the class to access the method
    * void: Your application need not return a value, as the JVM launcher would return the value when it exits
    * main(): This is the entry point for the application
  • Line 3: curly braces opens here or just immediately after method name
  • Line4 : Printing the String constant into the console
  • Line5 : close the bracket for method
  • Line 6 : close the bracket for class Java Demo
In order to run this program you have to compile this program into byte code by the command ->javac JavaDemo.java
And Run the program by typing the below command
-> java JavaDemo
You can see the following output
HelloWorld!
Share your thoughts

How to find occurence of a string in a file

Single occurrence
This java program helps to find the occurrence of a string in a file. It will print the location of the string in the console as output. You can use this program as append with the web application you developing or as a separate stand alone program

Expected input : file name, Search String

Code:
Given the utility method only

public void searchString(String fileName, String  searchText) {
StringBuilder sb = new StringBuilder();
String line=null;
try {
BufferedReader reader =new BufferedReader(new FileReader(fileName));

//Reads until the end-of-file met
while( null != ( line = reader.readLine() ) ){

//Read line-by-line directly
sb.append(reader.readLine());
}
} catch (IOException ex) {
ex.printStackTrace();
}
String fileText = sb.toString();
System.out.println("Position in file : " + fileText.indexOf(searchText));

}
multiple occurrence of the String in a file
By fine tuning the above program you can find the multiple occurrence of the String in a file by using the method given below. The input for the program is the individual lines getting from the file using the method readLine()



private Boolean  ifWordsExists(String line, String searchText, SearchBean fo) throws IOException  {
StringBuffer bf = null;
int index = 0;
Boolean flag = false;
if (line.indexOf(searchText) > -1) {
flag = true;

}
return flag;
}
Here it will returns the value true if the string find in the line supplied. And after setting the founded line in array list you can display it on the web application

Share your thoughts