Ektaa Gargg

Greenhorn
+ Follow
since Mar 08, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ektaa Gargg

I want to understand if variables declared outside /inside try block are /can be accessible to
catch block as well.

Please find a code template below:

Basically can i use Stmt like this inside catch block to capture exceptions(logging errors)

void insertException()
{

Connection conn = null;
PreparedStatement stmt = null;

try
{


}
catch(SQLException sqle)
{
String expQuery = "insert into tablename values(' ', ' ',' ');
stmt = conn.prepareStatement(expQuery); -- this should be again inside a try catch block
int catch1 = stmt.executeUpdate();
}

what can be the alternative to this.

Thanks

Ekta Garg
12 years ago
Hello Aleksander Switalski ,congrats!!!

You had mentioned SCWCD5 links site for information on scwcd exam but the link leads us to nowhere you mentioned ,i suppose its only for posting,is it?
15 years ago
I have created a file in NetBeans it is having a path for HTML files but when i compile and run that java file i am unable to get any HTML pages only the java utility opens up without opening the corresponding HTML pages.

Please help!
In the below code i am unable to put the implemetation of compareTo.Please help me with some code which can be inserted at " ? " in the compareTo method so that i get the output 12.

Also pls expalin me the method.

I tried with the following:

1) parameter- compareTo(x o)
return i.compareTo(i2.i)

And i am getting the compiler error as - x class did not implement the compareTo method(I know that compareTo itself implements for String and Integer types.)

----------------------------------------------------------------
import java.util.*;

public class x implements Comparable{

public static void main(String [] args) {

ArrayList<x> list = new ArrayList<x>();
list.add(new x(2));
list.add(new x(1));
Collections.sort(list);
System.out.println(list);
}

private int i;
public x(int i) { this.i = i;}
public String toString() { return Integer.toString(i); }

public int CompareTo(? o) {
x i2 = (x)o ;
return ? ;
What changes should i make in the below code so that it compiles & runs successfully :

Also i am looking forward to use only for-loop both normal and the enhanced for loop and not the while-loop to traverse through the list.

class x {
public static Iterator reverse(List list){
return list.iterator();
}

public static void main(String [] args){
List list = new ArrayList();
list.add("1");list.add("2");list.add("3");
for(Object obj:reverse(list))
System.out.print(obj + " " );
}
}
Please explain me how should i develop the technique to solve GC questions:
Also at any line in the following code, is a single object eligible for garbage collection n why?

public class Island {
Island n ;
public static void main(String [] args) {
Island i2 = new Island();
Island i3 = new Island();
Island i4 = new Island();

i2.n = i3;
i3.n = i4;
i4.n = i2;

i2 = null;
i3 = null;
i4 = null;
}
}
Please explain me the output:

class Tree {
private static String tree = "tree ";
string getTree() {return tree; }
}

class Elm extends Tree {
private static String tree = "elm ";
public static void main(String [] args) {
new Elm().go(new Tree());
}

void go(Tree t) {
String s = new Elm().getTree();
System.out.println(s);
}
}

I want to know that since getTree() is inherited by class Elm then why it does not use its own tree variable.