Swati Samudra

Greenhorn
+ Follow
since Dec 27, 2000
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 Swati Samudra

I have class A in Package P1 and its sub-class Class B in Package P2. I am able to compile class A from P1 directory on the prompt but I am Getting erro when I compile Class B from P2 directory at the prompt. I have import statement in class B importing class A and the error message says can't find class A and gives error at import statement.
How can I compile class B in package P2?
am confused....!
Swati
Hi Manfred,
Can you show me with the same example how Pass By Reference can be done. Because I have seen two separate examples for Pass By Value and Pass By Reference. But I don't know how to do it here.
I mean can we change the coding so that Pass By Reference is done and we get the revised value of x after multiplication. Or is it like that for variables we can never change the value.
Please explain.
[This message has been edited by Swati Samudra (edited January 19, 2001).]
23 years ago
In the mock exam I came across one question, which is as follows:
Q.
If you run the code below, what gets printed out?
String s=new String("Bicycle");
int iBegin=1;
char iEnd=3;
System.out.println(s.substring(iBegin,iEnd));
1) Bic
2) ic
3) icy
4) error: no method matching substring(int,char)

Ans.
2) ic
This is a bit of a catch question. Anyone with a C/C++ background would figure out that addressing in strings starts with 0 so that 1 corresponds to i in the string Bicycle.
The catch is that the second parameter returns the endcharacter minus 1. In this case it means instead of the "icy" being returned as intuition would expect it is only "ic".
I didn't get the catch, i.e "the second parameter returns the end character minus 1." What does it mean. I also could not analyse the answer that is second part of it.
Please, can anyone can do it for me.

[This message has been edited by Swati Samudra (edited January 19, 2001).]
23 years ago
Sajan,
I have found the solution to my problem. My classpath was not set to one-up, but one above the one-up in Autoexec.bat, so I was having the problem in compiling B.java. While compiling A.java I was making P1 as my current directory. But while compiling B.java if I made P2 as my current directory it would not able to find P1 package. So I had to set classpath to one-up above the package in my Autoexec.bat file and I was able to compile both the files.
Let me inform you, the program is just fine and runs with any i.e either superclass or subclass reference.
[This message has been edited by Swati Samudra (edited January 18, 2001).]
23 years ago
If I save class A in package P1 and class B in default package that is current directory. I am able to compile and run the program. Even if I give A a1=new A(); or B a1=new B(). I am not having any problem with this.
But I have another problem. If I save class A in package P1 and class B in another package P2. I am able to compile A.java by keeping my current directory P1. But I am not able to compile B.java. Because if I compile from P2 directory I am getting the message "package P1 does not exist" and if I compile from one-up directory I get "can't read B.java".
How can I compile B.java which is in another package, importing class from A.java which is another package.
I don't know how to do this. My problem is I am not able to compile file in different package which is importing classes from another package. From which prompt should I compile the file B.java.
23 years ago
Thanks Rob Acraman,
Even I was helped with this.
23 years ago
I also compiled and run the program and it's fine. I got the output.
However my path is:
PATH=c:\windows;c:\windows\command;D:\JDK1.3\BIN;
You can change the path by "set Path=%PATH%;D:\JDK1.3\Bin:" command at the prompt or by directly putting "PATH=c:\...etc".
I think it should help. I suppose the program is not able to find the path so it runs when you type -classpath.

[This message has been edited by Swati Samudra (edited January 18, 2001).]
23 years ago
Thanks Peter Tran,
I tried the coding. It's exactly what I was looking for but was not able to do the way you did it coz I was not using your first println statement:
System.out.println(sum+"+"+i+"=");
Thanks again.
[This message has been edited by Swati Samudra (edited January 18, 2001).]
23 years ago
I wan't to add integers 1 to 30. How can I do that in java.
I tried using for and while loop but failed to add the integers.
I only get 1,2,3 etc.But I wan't to add 1+2+3 etc.
It has to be
0 + 1 =1
1 + 2 =3
3 + 3 =6
6 + 4 =10
10 + 5 =15
15 + 6 =21 and so on
upto 30.
Please help me or tell me the other way I can do it in Java. Correct me if I am wrong.
23 years ago
I think I got that....I was taking JRE and Interpreters as two different things. I thought it was only the Java Interpreter that vendors always provided alongwith their software and JRE was some run time environment provided by SUN.
But it is the JRE which can be bundled or optionally not bundled by the software vendor. And JRE encompasses Java Runtime Interpreter. End-users can download and install the Windows JRE themselves if not provided by the vendor from Sun's Java software website. Once a user has installed the JRE, it can be used to run any number of Java applications. The JavaTM Runtime Environment (JRE) is the minimum standard Java platform for running applications written in the Java programming language. It contains the Java virtual machine*, Java core classes, and supporting files.
I also got related info from here: http://java.sun.com/products/jdk/1.1/runtime.html#intro
[This message has been edited by Swati Samudra (edited January 04, 2001).]
[This message has been edited by Swati Samudra (edited January 04, 2001).]
23 years ago
OK...with JRE we can run the programs on the computer system. That means even if you don't have JDK and you have JRE loaded on your PC you can run the java program.So JRE is atleast necessary for running the programs.
But does that mean interpreters are there on the Operating System and the JRE supports the task of an interpreter? Can I say it that way?
[This message has been edited by Swati Samudra (edited December 29, 2000).]
23 years ago
Suppose, I don't have JDK loaded on my computer, But I have a class file (after compiling .java file) which I transfer from another computer to my computer. Can I run the class file ? (i.e. execute the program since Interpreter is platform dependent and comes along with software as it is installed by the vendor on software.I have windows '98 and NT loaded on my PC).
Correct me.
23 years ago
Suppose, I don't have JDK loaded on my computer, But I have a class file (after compiling .java file) which I transfer from another computer to my computer. Can I run the class file ? (i.e. execute the program since Interpreter is platform dependent and comes along with software as it is installed by the vendor on software.I have windows '98 and NT loaded on my PC).
Correct me.
23 years ago
JVM
It is not possible to run the java program without JVM. I don't think so coz Interpreter in the JVM translates the java bytecodes in to executable program which is then run by the computer system.
23 years ago
Why there is need for translator if we have an interpreter that can understand the java language and execute the machine instructions?
If Interpreters could understand bytecodes then why not install the interpreters that could convert the java lang code in to machine instructions?
If there are interpreters for other languages then why not for Java?
Please increase my knowledge.
23 years ago