JAVA

PostPosted: Sept  29, 2012 9:35 am    Post subject: problem split string with dot in java Reply with quote

HiI have to use string split function in jsp for my need. I was using above than jdk1.4 version. but split string was not working.

My code was like

Code:
String moduleName=”tt.group”;String[] myModuleArr = moduleName.split(“.”);

System.out.println(“Length :”+myModuleArr.length);

It was showing 0;

Instead of using that we should use string split with \\.

Code:
String moduleName=”tt.group”;String[] myModuleArr = moduleName.split(“\\.”);

System.out.println(“Length :”+myModuleArr.length);

 

Many Public Classes in 1 Java File !!
There is a popular misconception among the beginners that we can have multiple public classes in one java source file.
But the rule is that “we can have atmost one public class and any number of non-public classes in one .java source file”. The public class must contain the main method, from where the execution begins. As i see it, this is so that JVM could access and call the main method from outside the class.

However, there is one exception to this rule. I wrote this blog entry because i came to know about the exception 🙂
The exception comes when we deal with inner classes. You can have as-many-as-you-want public inner classes in your class. But, it is not desirable as it results in difficult-to-manage code and of decreases its re-usability.

For example, the following code would compile and run successfully.
>
> class tryme
> {
> public static class A
> {
> public void print()
> { System.out.println(” Print inside A “); }
> }
>
> public static class B
> {
> public void display()
> { System.out.println(” Display inside B “); }
> }
>
> }
>
> public class test
> {
> public static void main(String[] args)
> {
> tryme.A ob = new tryme.A();
> ob.print();
>
> tryme.B ob2 = new tryme.B();
> ob2.display();
> }
> }
>

Of course, the file must be named test.java. It compiles and produces the following output.
>
> Print inside A
> Display inside B
>

Another way of using public inner classes is by importing them in your program like
import packagename.tryme.*;
and then use classes A and B as they you like.

But, the recommended style of programming discourages use of more than one public class in one java file. Also, such behaviour is not supported on all compilers. Infact, for maximum optimization (by compiler) it is recommended that you should write one class per java file.

Set path in order to Start tomcat in Browser
========================================================
->Go to MY compter FOLDER
->Right click and click on properties
->go to Advanced system settings
->CLICK ON ENVIEONMENT VARIABLES
->In system variables click on NEW
->SET variable name as JAVA_HOME and variable vaue as C:\Program Files\Java\jdk1.5.0_09
->In system variables click on NEW
->SET variable name as PATH and variable vaue as C:\Program Files\Java\jre1.5.0_09\bin
->CLICK ok

->Go to apache tomcat in driver which you have stored ex:C:\apache-tomcat-6.0.29\bin
->In bin folder click on startup.bat(=========server is started========)

->Go to Browser then type http://localhost:8080/

Leave a Reply to assist you..

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s