Tuesday, June 22, 2010

Eclipse key board shortcuts -Techies

Eclipse key board shortcuts :


Ctrl+space. Autocomplete.
This will recommend a list of classes they will fit what you have typed so far. If there is only one match, it will just print it out for you. After it does print it out for you, it will include the import for you. If something is ever missing the import at the top, I will just go to the Class declaration and just hit Ctrl+space.

Ctrl+Shift+O : Import packages:
This is very much required when we have to import packages for classes. (Organizing)

Ctrl+Shift+R. Open resource.
I cannot live without this shortcut. It is such a time saver. Whenever you are trying to find a specific class, just start typing it and it will populate which classes match that criteria. Once you found it, select it and there you go! It also works great if you are new to a framework and need to find certain classes or if you partly recall the class name but not 100% sure.

Ctrl+O. Show inherited members.
This is another one that works great when you are working with classes with a massive lump of methods attached to it. You COULD do this within the Package Explorer, but no one likes touching that mouse! You can even type to filter down your methods. If you have methods with the same name and just different parameters, this also works great. Just type in part of the method name and get a few overview and access to each of the methods.

Ctrl+H. Loads search box.
I cant tell you how often this saves me. This isnt just a ‘find’ box, this does a ‘find in files’ within the File Search tab. Within here, you can specify what you are looking for in the files, what you file types you want to search in, etc. There are other types of search you can use, but I have not run into a case where I need them. Have you?

Ctrl+Shift+C. Comments a block of code.
This is perfect for debugging. It is strange because really when you think about it, you are only talking about having something put a /* at the begging of what you selected and a */ at the end of what you selected. However, I use this a lot more often than you would expect.

Ctrl+D. Delete a line.
Self explanatory. Extremely useful. If I didn’t have that, I’d have to waste time with Shift+End, Delete!.

Ctrl+E. Menu for opened files.
This will bring up a list of opened files that you have. Not only that, it will also allow you to type in your class names to narrow down your choices.

Ctrl+Shift+E : Window for Opened files:
This key is used to view all the files opened in the editor , where it will be easy to identify & open the files .

Ctrl+1:
Is used for renaming variables at a time through out the file. Will be useful when we want to rename the variable name where the variable being used at many places.

F4. Shows class hierarchy.
This is extremely useful when you are new to a with a massive framework and you really want to get a sense of how things are all connect, who extends what, etc.

F3 and Ctrl+Left Mouse Click. Shows declaration.
I enjoy using this when I am working with larger files or anything with long methods (which always irks me). It can get extremely annoying to see where some variables are declared. All you have to do is high light the variable then hit F3. Sometimes I will hold control and hover over variable names if I am having a problem.

F5, F6, F7, F8. In debug mode.
There three shortcuts are probably used more than anything. I wanted to group them all into one section.

F5 – Step Into. When you are debugging an application and you come across a function call, F5 will step into that function and proceed from there.

F6 – Step. This allow you to debug line by line. However, this will not step into any functions.

F7 – Step out. If you are debugging in a function and you want to step out of it to where the function was called, this is what is used.

F8 – Skip to next breakpoint. If there arent any other break points to high, you will be just running the application until your application hits another breakpoint, taking you back into debug mode.

Alt+leftarrow or Alt+rightarrow. Jump back to a line, Jump forward to a line.
According to eclipse, this is “Next word, Previous word’. I am not sure what that means. All I know if I am stepping into functions, debugging through multiple files and breakpoints, this is a life saver. It allows me to retrace my steps, step by step. If I go back with Alt+leftarrow, I can go right back to where I was with Alt+rightarray.

Ctrl+Shift+L. Displays all shortcuts.
Self explanitory. Dig in and find your favorite!This last one is not about using a shortcut. It is about what you have to do to turn it of.

Ctrl+W or Ctrl+F4: close the single file.
This is used to close the current file that is opened in the editor.

Ctrl+Shift+W or Ctrl+Shift+F4 : Close all the files:
When many files we have opened this is very much useful to close all the files opened in the editor in a single shot.

Alt + left key : Navigation
This is used to navigate from one page to another page in the left direction .

Alt+right key : the same as above for right navigation.

Ctrl+Shift+/ : comment
This is used to add the block level comment in a page.

Ctrl+Shift+\ : remove comment

Ctrl+Shift+F : Formatting contents

Save your time using keyboard.......
 
Rocking,
Shyamala

Saturday, June 19, 2010

ECLIPSE DEBUGGING TUTORIAL

Debugging Using eclipse :

Let us consider one simple Java project :

Where i have created in the following manner.












Presently it is in java perspective.......

we can change the perspective into debugging by clicking WINDOW-->Open perspective ---> and go

to other and select “Debug”.

Then :











We can add the break point lines by double clicking on the line in source code...

  • You can observe clearly there are areas EXECUTION STACK,WATCH VARIABLES AND EXPRESSION AREA,SOURCE CODE Area,and as well CONSOLE SCREEN.

Observe the following screen shot to add watch expression as well as execution environment













  •   By using F11 key we can start debugging any Java application.
               Here in this case i have added two watch expression one is “i” value and another is “str1” value.

  •   By using F6 key we can do step by step execution of a program.

  • By using F8 key we can skip the current break point it will be jumping into the next break point start.

 Observe the next screen shot which shows the values of “i” & str1













Thats it ..............

This is simple debugging of Java application.

JUST SCROLL DOWN........













This is how it will be after termination of Program...which stops with THREAD....

Very much required as a developer to know how to use Eclipse debugging ......as in the real world applications development no body will prefer using System.out.println();......


So be the best by learning & practicing this .....

Keep Rocking
Shyamala

Tuesday, April 13, 2010

Displaying IP Address of the system using Runtime

Runtime is a class which is specifically made for the purpose to run any kind of process using "exec" method

import java.io.*;
class DisplayIP{
public static void main(String args[]){

Runtime runtime = Runtime.getRuntime();
try{
Process process = runtime.exec("cmd.exe /c ipconfig");
InputStream in = process.getInputStream();
int ch = in.read();
while(ch!=-1){
System.out.print((char)ch);
ch=in.read();
}
in.close();
}
catch(IOException e){
System.out.println(e);
}
}
}

Still any doubt !!! check out by clicking the link
http://www.java-tips.org/java-se-tips/java.util/from-runtime.exec-to-processbuilder.html
Cheers
Shyamala

Deep Copy vs Shallow Copy in C++

Usually in c++ we will be more confused about these constructors about deep copying & shallow copying.....

Here is a simple example where there is a class called String where we have to strings which is used to store firstname ,lastname and the age of the person.

Where in case of this I am creating the Object of String with the name s1 which after reading the details I am assigning it to one more Object s2.



#include<iostream.h>
#include<string.h>
#include<conio.h>

class String
{
char *firstname; // declaring pointer to store string
char *lastname;
int age;

public:
String()
{
firstname = new char[30];
lastname = new char[30];
age=0;
}
void read()
{
cout<<"\n Enter name:";
cin>>firstname>>lastname;
cout<<"\n age :";
cin>>age;
}
void print()
{
cout<<"\n name is "<<firstname<<" "<<lastname;
cout<<"\n Age :"<<age;
}
~String()
{
delete[]firstname;
delete[]lastname;
}
};

void main()
{
clrscr();

String s1;
s1.read();
s1.print();

String s2=s1; //assigning the object s1 to s2
s2.print();

s1.read();

s1.print();
s2.print();

getch();
}

U can observe after u make any changes to the s1 object with the Strings that is firstname,lastname it will be reflected in s2 object also.

So by default there is one copy constructor given for you in your c++ classes which will be of this prototype which just assigns the values using "=" operator.

Prototype of Copy constructor:
ClassName(ClassName &Object){
}
This is "SHALLOW COPYING"
For the above class :
String(String &s){
firstname=s.firstname;
lastname=s.lastname;
age = s.age;
}

To over come this problem where it should be allocated with the own memory allocations just keep this below code and observe which is called "DEEP COPYING"

String(String &s)
{
cout<<"\n copying......";
int l1= strlen(s.firstname)+1;
int l2= strlen(s.lastname)+1;
firstname = new char[l1];
lastname = new char[l2];
strcpy(firstname,s.firstname);
strcpy(lastname,s.lastname);
age=s.age;
}


SHALLOW COPYING IS DEFAULT DONE .......WHICH OVERLOADS "=" operators.

DEEP COPYING YOU SHOULD WRITE ON YOUR OWN!!

Cheers
Shyamala

Saturday, April 10, 2010

SCJP Questions

Question 1 :
class Demo{
public static void main(String args){
System.out.println("welcome to java");
}
}

What will be the output of the program:
a) Error at compile time b) Error at Runtime
c) prints welcome to java d) No Error and no output

===============================================================
Question 2:
Which of the following are legal statements in Java?
a) float f=1/3; b) float f=1.01;
c) int i=1/3; d) double d=999d;

===============================================================
Question 3:
What will happen when you compile and run the following code?
public class MyClass{
static int i;
public static void main(String argv[]){
System.out.println(i);
}
}
a) Error Variable i may not have been initialized c) 1
b) null d) 0

===============================================================
Question 4:
class Demo{
static void print(){
System.out.println("Hello");
}
public static void main(String args){
Demo d =null;
d.print();
}
}

a) Error at compile time b) Error at Runtime
c) prints Hello d) No Error and no output

===============================================================Question 5:
Which of the following statements are true?
a) A byte can represent between -128 to 127
b) A byte can represent between -256 to 256
c) A byte can represent between -127 to 128
d) A char can represent between -2x2 pow 16 2 x2 pow 16 - 1

===============================================================Question 6:
Which of the following statements are true?
a) Constructors cannot have a visibility modifier
b) Constructors can only have a primitive return type
c) Constructors can be marked public and protected, but not private
d) Constructors are not inherited

===============================================================Question 7:
What will happen when you attempt to compile and run the following class?
class Base{
Base(int i){
System.out.println("Base");
}
}
class Severn extends Base{
public static void main(String argv[]){
Severn s = new Severn();
}
void Severn(){
System.out.println("Severn");
}
}
a) Compilation and output of the string "Severn" at runtime
b) Compilation and no output at runtime
c) Compile time error
d) Compilation and output of the string "Base"

===============================================================Question 8:
Given the following code
class Base {}

class Agg extends Base{
public String getFields(){
String name = "Agg";
return name;
}
}
public class Avf{
public static void main(String argv[]){
Base a = new Agg();
//Here
}
}
What code placed after the comment //Here will result in calling the getFields method resulting in the output of the string "Agg"?
a) System.out.println(a.getFields());
b) System.out.println((Base) a.getFields());
c) System.out.println(a.name);
d) System.out.println( ((Agg) a).getFields());

===============================================================Question 9:
What will happen when you attempt to compile and run the following code?
public class Inc{
public static void main(String argv[]){
Inc inc = new Inc();
int i =0;
inc.fermin(i);
i = i++;
System.out.println(i);
}
void fermin(int i){
i++;
}
}
a) Compile time error b) Output of 1
c) Output of 2 d) Output of 0

===============================================================Question 10:
Given the following class
public class Ombersley{
public static void main(String argv[]){
boolean b1 = true;
if((b1 ==true) || place(true)){
System.out.println("Hello Crowle");
}
}

public static boolean place(boolean location){
if(location==true){
System.out.println("Borcetshire");
}
System.out.println("Powick");
return true;
}
}
What will happen when you attempt to compile and run it?
a) Compile time error
b) Output of Borcetshire and Powick followed by "Hello Crowle"
c) Output of "Hello Crowle"
d) No output
===============================================================Question 11:
What will happen when you attempt to compile and run the following code?
public class Sandys{
private int court;
public static void main(String argv[]){
Sandys s = new Sandys(99);
System.out.println(s.court);
}
Sandys(int ballcount){
court=ballcount;
}
}
a) Compile time error, the variable court is defined as private
b) Compile time error, s is not initialized when the System.out method is called
c) Compilation and execution with no output
d) Compilation and run with an output of 99
===============================================================
Question 12:
Given the following code
class Base{
static int oak=99;
}
public class Doverdale extends Base{
public static void main(String argv[]){
Doverdale d = new Doverdale();
d.amethod();
}
public void amethod(){
//Here
}
}
Which of the following if placed after the comment //Here, will compile and modify the value of the variable oak?
a) super.oak=1; b) Base.oak=22;
c) oak=33; d) oak=50.1;
===============================================================Question 13:
Which of the following statements are true?
a) A method cannot be overloaded to be less public in a child class
b) To be overridden a method only needs the same name and parameter types
c) To be overridden a method must have the same name, parameter and return types
d) An overridden method must have the same name, parameter names and parameter types
===============================================================Question 14:
You want to loop through an array and stop when you come to the last element. Being a good java programmer and forgetting everything you ever knew about C/C++ you know that arrays contain information about their size. Which of the following can you use?

a)myarray.length();
b)myarray.length;
c)myarray.size
d)myarray.size();
===============================================================Question 15:
What will happen when you attempt to compile and run this program
public class Outer{
public String name = "Outer";
public static void main(String argv[]){
Inner i = new Inner();
i.showName();
}//End of main
private class Inner{
String name =new String("Inner");
void showName(){
System.out.println(name);
}
}//End of Inner class
}
a) Compile and run with output of "Outer"
b) Compile and run with output of "Inner"
c) Compile time error because Inner is declared as private
d) Compile time error because of the line creating the instance of Inner
===============================================================Question 16:
Given the following class definition, which of the following methods could be legally placed after the comment //Here

public class Rid{
public void amethod(int i, String s){}
//Here
}
a)public void amethod(String s, int i){}
b)public int amethod(int i, String s){}
c)public void amethod(int i, String mystring){}
d) public void Amethod(int i, String s) {}
===============================================================Question 17:
public class Test7{
public Test7(){}
public Test7(Test7 ref){
this (ref,"Hai");
}
public Test7(Test7 ref,String str){
ref.Test7(str);
System.out.println("Hi");
}
public void Test7(String str){
System.out.println(str);
}
public static void main(String[] args){
Test7 t = new Test7();
Test7 t7 = new Test7(t);
}
}
a) HI b) hai
c) Hai Hi d) Hi Hai
===============================================================Question 18:
What will be the output of the following program?

class Sup1{
public Sup1(){
System.out.println("Hai");
}
private Sup1(String str){
System.out.println(str);
}
}

public class Test5 extends Sup1{
private Test5(String str){
System.out.println(str);
super();
}
public static void main(String[] args) {
Test5 t5 = new Test5("HI");
}
}

a) Hai,Hi,Hi b) Hai,Hi
c) Hi,Hi d) Compiler Error
===============================================================Question 19:
class VarArgOne {
public static void printArgs(String s, int ... i, String s) { //line1
for(int j : i) { //line 2
System.out.print(j + " " + s); //line 3
}
}
public static void main(String ... args) { //line 4
printArgs("exam", 12, 34, "scjp"); //line 5
}
}
a) Compilation fails due to error at line 1.
b) Compilation fails due to error at line 2.
c) Compilation fails due to error at line 4.
d) Compilation fails due to error at both line 1 and line 4.
e) Compiles fine and Prints output "12 scjp 34 scjp".
===============================================================Question 20:
class A{
private void print(){
System.out.println("===print in A===");
}
}
class B extends A{
void print(){
System.out.println("===print in B===");
}
}
class M{
public static void main(String args[]){
A ref = new B();
ref.print();
}
}
What happens when we try to compile the above program:
a)Error at compile time b)Error at run time
c)prints print in A d) prints print in B
===============================================================Question 21 :
interface I{
void print();
}
class A{
static void print(){
System.out.println("===print in A===");
}
}
class B extends A implements I{
public void print(){
System.out.println("===print in A===");
}
}
class M{
public static void main(String args[]){
A ref = new B();
ref.print();
}
}
What will be the output & Write explanation?
===============================================================Question 22:
What all gets printed when the following code is compiled and run? Select the three correct answers.
public class xyz {
public static void main(String args[]) {
for(int i = 0; i < 2; i++) {
for(int j = 2; j>= 0; j--) {
if(i == j) break;
System.out.println("i=" + i + " j="+j);
}
}
}
}
===============================================================Question 23:
What is the result of compiling and running the following program. Select the one correct answer.
class test {
public static void main(String args[]) {
int[] arr = {1,2,3,4};
call_array(arr[0], arr);
System.out.println(arr[0] + "," + arr[1]);
}
static void call_array(int i, int arr[]) {
arr[i] = 6;
i = 5;
}
}
a. 1,2 b. 5,2
c. 1,6 d. 5,6
===============================================================Question 24:
Assume that class A extends class B, which extends class C. Also all the three classes implement the method test(). How can a method in a class A invoke the test() method defined in class C (without creating a new instance of class C). Select the one correct answer.
a. test();
b. super.test();
c. super.super.test();
d. ::test();
e. C.test();
f. It is not possible to invoke test() method defined in C from a method in A.
===============================================================Question 25:
Which of the following are legal array declarations. Select the three correct answers.
a. int i[5][]; b. int i[][];
c. int []i[]; d. int i[5][5];
e. int[][] a;
===============================================================
ALL THE BEST

Difference Between String VS StringBuffer VS StringBuilder

Shown below is an example that concatanates 10000 strings using the '+' operator, StringBuffer, and StringBuilder, and prints the operation time in nanoseconds. The ability to get time in nanoseconds is another feature that was added in JDK 1.5.

public class StringConcatanations {
public static final int MAX_ITER = 10000;

public static void main(String[] args) {
concatenate();
concatenateWithStringBuffer();
concatenateWithStringBuilder();
}

public static void concatenate() {
System.out.println("Concatanating using the + operator");
String s1 = "";
long s1Time = getNanoTime();
for(int i=0;i) {
s1 = s1 + "abc";
}
long e1Time = getNanoTime();
System.out.println("Time: " + (e1Time - s1Time));
}

public static void concatenateWithStringBuffer() {
System.out.println("Concatanating using StringBuffer");
StringBuffer sb = new StringBuffer();
long s2Time = getNanoTime();
for(int i=0;i) {
sb.append("abc");
}
long e2Time = getNanoTime();
System.out.println("Time: " + (e2Time - s2Time));
}

public static void concatenateWithStringBuilder() {
System.out.println("Concatanating using StringBuilder");
StringBuilder sBuilder = new StringBuilder();
long s3Time = getNanoTime();
for(int i=0;i) {
sBuilder.append("abc");
}
long e3Time = getNanoTime();
System.out.println("Time: " + (e3Time - s3Time));
}

public static long getNanoTime() {
return System.nanoTime();
}

}


Output:
Concatanating using the + operator
Time: 744597428
Concatanating using StringBuffer
Time: 1685131
Concatanating using StringBuilder
Time: 1317206


Check out the time taken to append the String using "+" operator!!

As you can see, if you do not need thread safety, StringBuilder yeilds the best result, followed by Stringuffer, followed by the '+' operator. However, if you do need thread safety, then StringBuffer is your natural choice.

Cheers

Shyamala


Monday, March 15, 2010

EL functions in JSP

EL Functions:
Very simple used to invoke any functions with names.......

For Ex:

create a class as below:com.fun.Message

package com.fun;
/*
* A class Which contains the user defined funcion sayHello
*/
public class Message{

public static String sayHello(){

return "hello!!";
}
}

Keep this .class under /WEB-INF/classes/com/fun/Message.class


Then we have to create TLD file which describes your functions :
myfucntions.tld:

<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.1</jsp-version>

<function>
<name>hello</name>
<function-class>com.fun.Message</function-class>
<function-signature>java.lang.String sayHello()</function-signature>
</function>

<function>
<name>rand</name>
<function-class>java.lang.Math</function-class>
<function-signature>long random()</function-signature>
</function>

<function>
<name>absolute</name>
<function-class>java.lang.Math</function-class>
<function-signature>int abs(int)</function-signature>
</function>

</taglib>

You can observer this TLD is describing some predefined functions of java.lang.Math class also.

Save this file as " myfunctions.tld" keep this under /WEB-INF folder of your application.

"name" tag in function is necessary with that name only user is going to call the functions.

Then at last create your jsp:

<%@page isELIgnored="false" %>
<%@taglib uri="/WEB-INF/myfunctions.tld" prefix="f" %>

${f:hello()}
${f:rand()}
${f:abso lute(10)}


Rocking
Shyamala

Tuesday, March 9, 2010

Difference between @include & jsp:include

To get to know the difference between these two

<%@include file="" %> is a directive

Action tag:

<jsp:include page="{relativeURL | <%= expression %>}" flush="true" />
or
<jsp:include page="{relativeURL | <%= expression %>}" flush="true" >

<jsp:param name="parameterName"

value="{parameterValue | <%= expression %>}" />

</jsp:include>



one.jsp
=========

<%@page isELIgnored="false"%>

<jsp:declaration>int cnt=0;</jsp:declaration>
<jsp:expression>"Shyamala"+cnt++</jsp:expression>
<jsp:include page="two.jsp"/>

two.jsp
==========
I am just included

now go to work directory of tomcat and check out there will be two seperate servlets created

and even u can observe one line in one_jsp.java file
org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "two.jsp", out, false);

which specifies the page is included at run time

just change your one.jsp file as following

one.jsp

<%@page isELIgnored="false"%>


<jsp:declaration>int cnt=0;</jsp:declaration>
<jsp:expression>"Shyamala"+cnt++</jsp:expression>
<%@ include file="two.jsp"%>

you will not be created with two different java files in work directory the two.jsp contents also will be included in the same one_jsp.java file.

That means it is done at the time of compilation!!


Rocking !!
Shyamala

Saturday, February 20, 2010

Calendar of a month using Java

import java.util.*;
/*
* Printing the calendar of a month where the user
* Gives the input month , year
* By Shyamala
*/
class CalendarForMonth{
public static void main(String args[]){
//A string array for months

String months []={"Jan","Feb","March","April","May","June","July","Aug","Sept","Oct","Nov","Dec"};

//An integer for number of days in every month
int nDays[]={31,28,31,30,31,30,31,31,30,31,30,31};

//creating the instance of calendar
Calendar calendar = Calendar.getInstance();

Scanner in = new Scanner(System.in);
//Take the input from the user Month,Year

System.out.print("Enter month ,year :");
int mon = in.nextInt(); int yr = in.nextInt();
calendar.set(yr,mon-1,1); //setting date yr,mon,date consider first day

if(yr%4==0){
System.out.println("Leap year!!");
//change the number of days Feb month as it is leap year
nDays[1]=29;
}

System.out.println("Calendar For "+calendar.get(Calendar.YEAR)+" == "+months[calendar.get(Calendar.MONTH)]);

//printing the days
System.out.print("S\tM\tTu\tW\tTh\tF\tSa");
int day = calendar.get(Calendar.DAY_OF_WEEK);
//System.out.println(day);
System.out.println();

//gives you the starting day
int nline=0;
//for getting new lines

for(int i=1;i<=nDays[mon-1];i++){
System.out.print(i+"\t");
nline++;
if(nline%7==0)
System.out.println("\n");
}

}

}

Monday, January 18, 2010

String vs StringBuffer vs StringBuilder

Difference between String , StringBuffer and StringBuilder :


Let us first write one sample program using Java String:

Program:

class Demo{
public static void main(String args[]){
String s ="shyamala";
System.out.println("java"+s);
}
}


compile the above program and run u get the output as : javashyamala
then after this see the description about the bytecode using

cmd/> javap -c Demo

Compiled from "Demo.java"
class Demo extends java.lang.Object{
Demo();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."":()V
4: return
public static void main(java.lang.String[]);
Code:
0: ldc #2; //String shyamala
2: astore_1
3: getstatic #3; //Field java/lang/System.out:Ljava/io/PrintStream;
6: new #4; //class java/lang/StringBuilder
9: dup
10: invokespecial #5; //Method java/lang/StringBuilder."":()V
13: ldc #6; //String java
15: invokevirtual #7; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
18: aload_1
19: invokevirtual #7; //Method java/lang/StringBuilder.append:(Ljava/lang/ String;)Ljava/lang/StringBuilder;
22: invokevirtual #8; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
25: invokevirtual #9; //Method java/io/PrintStream.println:(Ljava/lang/String;)V
28: return
}

observe the highlighted lines in the above bytecode where by inbuilt it is using StringBuilder class when it is creating string.When we are using "+" operator with the strings it invokes append method of stringBuilder.

GC will be invoked manier times in case of String as once the string literal is not used again it should invoke Garbagecollector.


Other options include with javap:

javap -c Demo
to print Java1 Virtual Machine bytecodes,

javap -l Demo
to display line number and local variable tables (you need to compile perf.java with -g for this to work), and

javap -p Demo
to print private methods and fields in addition to the public ones.
javap is a handy tool for digging beneath the surface to find out what's really going on in a .class file.


About string :
1)Immutable class
2) Not thread safe

the performance is higher as it is using StringBuilder but when it is required frequent appending to a string better to go for stringBuffer which is mutable as well thread safety class.

StringBuilder
1) Mutable
2)Not threadsafety

StringBuffer:
1)Mutable
2)Threadsafety

http://java.sun.com/developer/TechTips/1998/tt0120.html#tip1
Thats it any queries get back to me!!!