sudha siva

Ranch Hand
+ Follow
since Sep 18, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by sudha siva

Hai All,

Can anyone explain me what is session objects.

Thanx
sudha
23 years ago
Hai All,
What is port? Please explain me in detail.
Thanks
sudha
23 years ago
JSP
Hai All,
Please have a look at the following code.

class Test {
public static void main(String[] args) throws Throwable {
int ia[][] = { { 1 , 2}, null };//line1
int ja[][] = (int[][])ia.clone();
System.out.print((ia == ja) + " ");
System.out.println(ia[0] == ja[0] && ia[1] == ja[1]);
}
}
Can we assign a null value to the array of int type.

Thanks
sudha
Hai Everyone,
Please have a look at the following code.

class Test{
public static void main(String args[]){
StringBuffer s=new StringBuffer("java");
StringBuffer s1=new StringBuffer("java");
System.out.println(s.equals(s1));
}
}

equals() of the above StringBuffers returns false.But both of them has the same value "java". So equals() should return true. Can anyone explaim me why the output is false.

Thanks
sudha
Hai Everyone,
public class TestClass3{
static String str = "Hello World";
public static void changeIt(String s)
{
s = "Good bye world";
System.out.println(s);
}
public static void main(String[] args)
{
changeIt(str);
System.out.println(str);
}
}

The value of "s" in changeIt() is "Good bye World". But it should be "Hello World" becoz
we are passing the "str" to ChangeIt() as an argument. I'm confused of the output. Can anyone clear my doubt.

Thanks
sudha
Hai All,
public class Conversion
{
public static void main(String[] args)
{
int i = 1234567890;
float f = i;
System.out.println(i - (int)f);
}
}
The output of the code is -46. Can anyone explain me how.
Thanks in advance
sudha
Hai Ranchers,
Sorry for posting a lot of questions. Please have a look at the following code.
import java.util.*;
public class Question1 {
public static void main(String args[]){
HashSet s=new HashSet();
String s1="abc",s2="def",s3= " ";
s.add(s1);
s.add(s2);
s.add(s1);
s.add(s2);
Iterator i=s.iterator();
while(i.hasNext()){
s3 += (String)i.next();
}
System.out.println(s3);
}
}

The final value of the String s3 is "defabc" . I thought it should be "abcdef". I don't know how it is reversed.Can anyone clear my doubt.

Thanks
sudha
class Test2
{
public static void main(String[] args)
{
int d = 0;
try
{
int i = 1 / (d* doIt());
} catch (Exception e)
{
System.out.println(e);
}
}
public static int doIt() throws Exception
{
throw new Exception("Forget It");
}
}
The output of the above code is java.lang.Exception Forget it.I don't how the Forget it in doIt() printed out.Can anyone explain me.

Thanks
sudha
Hai All,
Have a look at the following code.

public class TestClass
{
int i1 ;
static int i2;
public void method1( )
{
int i ; //Line 1
this.i2=i1;
}
public static void main(String args[]){
System.out.println("java");
}
}

i is a local variable in line 1. We need to initialize the local variable at the point if declaration.But in line1 i is not initialized.Moreover i'm not getting any compile time error.
I don't know why.can anyone clear my doubt.

Thanks
sudha
Hai Everyone,
class Counter {
public int startHere = 1;
public int endHere = 100;
public static void main(String[] args) {
new Counter().go();
}
void go() {
Runnable a = new Runnable() { // line 1
public void run() {
for (int i = startHere; i <= endHere; i++){
System.out.println(i);
}
}
};

Thread t = new Thread(a);
t.start();
}
}

Interfaces can't be instantiated.But in line1 "Runnable" object is created.This question is from jq+.In that it is mentioned as an anonymous inner class.I'm not able to understand the above code.Can anyone help me.

Thanks
sudha
Hai everyone,
class Test{
public static void main(String args[]){
int x=0;
boolean b1,b2,b3,b4;
b1=b2=b3=b4=true;
x=(b1 | b2 & b3 ^b4) ? x++ : --x; // line 1
System.out.println(x);
}
}

The output of the above code is 0.And in the answer the line 1 is evaluated as (b1 | (b2 & (b3 ^ b4)).But the AND operator should be evaluated first in this type of expression.(I think i,m correct).I'm confused of this code.Can anyone clear my doubt.

Thanks
sudha
Hai All,

class Question{
public static void main(String args[]){
for(int i=0;i<10;i++){
try{
try{
if(i % 3 == 0)
throw new Exception("EO");
System.out.println(i);
} catch (Exception inner){
i *= 2;
if(i % 3 == 0)
throw new Exception("E1");
} finally{
++i;
}
}catch(Exception outer ){
i+= 3;
}finally{
--i;
}
}
}
}
Can anyone tell me how the above code is executed(I mean the order of execution and the output).

Thanks
sudha
Hai Malar,
Sorry for the late reply. Here is one link for a list of mock exmas.
http://www.javaranch.com/maha/_Mock_Exams/_mock_exams.html
I'm getting questions from these list of mock exams.
Thanks
sudha
public class ADirtyOne1
{
public static void main(String args[])
{
System.out.println(Math.abs(-34));
System.out.println(Integer.MIN_VALUE);
System.out.println(Math.abs(Integer.MIN_VALUE));// line 3
System.out.println(Float.MIN_VALUE);
System.out.println(Math.round(Float.MIN_VALUE)); //line 5
}
In the above code the abs value of line 3 is negative. But the abs() should give the value without any negative sign. (Am I right).Can anyone claer my doubt and try to explain the round() in line 5.

Thanks
sudha
public class AnotherDirtyOne
{
private final int i =10;
private byte k = i; // line 1
}

public class AnotherDirtyOne{
private int i=10;
privete byte k=i;// line 2
}
The compiler is objected in line 2.(Explicit cast needed to convert int to byte.) But there was no compiler error in line 1.In line 1 also int value is assigned to byte variable.Can anyone tell me why there was no compiler erroe in line 2(Is it because of the final)

Thanks
sudha