Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

gururaj kulkarni

Greenhorn
+ Follow
since Sep 15, 2000
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 gururaj kulkarni

Hello!
In the following program Iam closing inputStream after reading 5 members.
But after closing also it is reading next 4 numbers.
Willu just clarify??
import java.io.*;

class ByteArrayInputStreamDemo
{

public static void main(String z[]) throws IOException
{
byte b[]={97,98,99,100,101,102,103,104,105};

ByteArrayInputStream input1=new ByteArrayInputStream(b);


//while(( x=input1.read())!=-1)
for(int i=0;i<5;i++)
{

int x=input1.read();
System.out.print(x+" ");
}

System.out.println("the num of unread bytes are"+input1.available());
System.out.println("Stream is closed");
input1.close();
for(int i=0;i<4;i++)
{
int x=input1.read() ;
System.out.print(x+" ");
}
}
}
21 years ago
Hello Akshay,
String in java is not treated as odinary primitive datatypes.
consider the following.
int a=100;
Double b=300.50;
String s="akshay";
u may ask WHY? Because String Handling will become very easy if u
treat strings as objects of class called String.
Even u can treat ordinary variables as objects ,if u wrap them
in classes.So that u can use all facilities provided by classes
by using them.
then ur next question will surely "Then still why to use ordinary variables?".
The answer is here.
The java API treats ordinary variables & objects differently.
By treating them as objects u will get a lot of facilities but
the API has to do a lot than for ordinary variables..
So for usual jobs it is better to deal with ordinary variables.
.......Gururaj
21 years ago
THANKS, Eric

From ur answer i got what is happening?
I have gone through ur example.Just for reading x we have to do so much?Suppose i want to read 10 different numbers of different types,then u can imagine the complexity? Is reading from keyBoard is so much complex?.
Also if u r free try to give solution to my problem that i have given in first letter.
with regards..
....Gururaj
21 years ago
Hell0!

I have tried to run this program.
I have entered value of x as 1,but it printed x as 49 & automaticaly printed y some value.
I want to enter x as 1 & y as 2.i want to get same results.
HOW?
import java.io.*;
class Ex8
{
public static void main(String a[]) throws IOException
{
System.out.println("enter a number");
try{
System.out.println("enter x");
int x;
x=System.in.read();
System.out.println("x is"+x);
System.out.println("enter y");
int y;
y=System.in.read();
System.out.println("y is"+y);
}
catch(Exception e)
{
System.out.println(e);
}

}
}

21 years ago
Hello!
In the First Part s1& s2 are not Pointing tosame object
but in the second part s10 & s20 are pointing to same objet.
THIS IS WHY?
class StringClass1
{
public static void main(String z[])
{
//first part
String s1="hello";
String s2=new String("hello");

if(s1==s2)
{
System.out.println("Both refer to same object");
}
else
System.out.println("Both are not refering to same object");

//second part

String s10="hello";
String s20="hello";

if(s10==s20)
{
System.out.println("Both refer to same object");
}
else
System.out.println("Both are not refering to same object");

}
}
21 years ago