Sanjeet Karamchandani

Ranch Hand
+ Follow
since Jul 29, 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 Sanjeet Karamchandani

Hi,
Its my time know to write. I am very happy to inform u all that i have passed the SCJP exams with 95% marks. Im a frequent visiter to this site and this site has provided me lot of help. I would also like to thank all of u who have help me.
It wasn't easy though coz i got questions on sockets(2), mediatracker(1), FilterInputStream(1) and many more. There were around five confusing onces as well. Two on threads, one on GC, one on encapsulation, one on GridBag.
This is how the question came :
5 on threads, out of that two were confusing.
4 on GC, 1 was really bad
3-4 on exception handling
2 on sockets
1 on mediatracker
1 on filterinputstream(never heard of questions on this)
and lots of them on overriding, overloadig, initialization, language fudas.
I hope it helps and Best of luck to all those who r going to give this exam.

Thanks
Sanjeet
I/O
Hi,
Manyways of diong it
BufferedReader buf = new BufferedReader(new FileReader(filename));
buf.readLine();
Then if u want to use streams
DataInputStream dis = new DataIunputStream(new BufferedInputStream(new FileInputStream(filename)));
dis.readLine() //note this is deprecated, so the first way s the moe preferred one
Thanks
Sanjeet

Originally posted by manal:
ya paul ... i wanna read a text file line by line ...


Hi snyd1437 & chengx,
R u both trying to say that option d is correct. Well, i have tried it and option c seems right and logical coz by in flowlayout the defalut allignment is Centre and not left.
Try it.
Thanks
Sanjeet

Originally posted by snyd1437:
You are correct except, BorderLayout defaults to BorderLayout.CENTER if no location is specified in add() which would mean the panel would be displayed in the center (vert and horiz) of the screen.


Hi,
public class Arg{
String []MyArg;
public static void main(String argv[]){
MyArg=argv; //1
}
public static void amethod(){
System.out.println(argv[1]);
}
}
Look closely at //1 , trying to acces non-static member of the class in a static method..which is not allowed. u have to create an instance fo Arg and change the statement as say
Arg a = new Arg();
a.MyArg = argv;

Thanks
Sanjeet
Plz let me know if anything is wrong
Hi
I know this Question is already discussed many times but this example is strange. Before trying this example i thought static methods r not overridden and i still have the same view, but with a doubt.
This example doesn't compile in its present form and gives a compile time error.
import java.io.*;
public class StaticException extends StaticExceptionBase{
public static void method() throws CloneNotSupportedException { }
}
class StaticExceptionBase {
public static void method() throws IOException { }
}
The Error message :
C:\Java\ex> javac StaticException.java
StaticException.java:4: The method void method() declared in class StaticException cannot override the method of the same signature declared in class StaticExceptionBase. Their throws clauses are incompatible.
public static void method() throws cloneNotSupportedException { }
^
1 error
It says the method cannot override coz the throws clause r different, thatz it. so if u change it it works. Doesn't that mean something strange. i mean doesn't it make u think that static methods r overridden.
import java.io.*;
public class StaticException extends StaticExceptionBase{
public static void method() throws IOException { }
}
class StaticExceptionBase {
public static void method() throws IOException { }
}
I request the moderators, if possible couldn't they ask someone from Sun Microsystems.
Thanks
Sanjeet
Hi,
Thes r from Ibm's exam :
21) AWT components get their look and feel from:

a) Programmable painting support classes
b) SWING classes
c) Peer classes
d) JVM drawing primitives
my ans : c

25) Based upon the code below, which of the answers apply?
1. public class TestFrame extends Frame {
2. public TestFrame(String title) {
3. super(title);
4. enableEvents(AWTEvent.WINDOW_EVENT_MASK);
5. }
6.
7. public void
processWindowEvent(WindowEvent we) {
8. System.out.println("Window event processed");
9. }
10. }

a) The window listener that has been added to TestFrame will be called on every window event.
b) This code will compile and run if a window listener is added to an instance of TestFrame.
c) An exception will be thrown if a window listener is added to TestFrame.
d) The window listener that has been added to TestFrame will never get called.
e) This code will not compile if a window listener is added to TestFrame.

my ans : d
Plz help me. Also provide proper reasons for it.
Thanks
Sanjeet
Hi,
int i=10;
// Following need explicit cast in order to get compiled.
char c=i; byte b=i; short s=i;
//But Following works fine - compiles well.
char c=10; byte b=10; short s=10;
Well, try this
final int i=10;
char c=i;byte=i;short=i;
All these assignments work well coz some optimization done by the compilier( Im not very sure what they mean by optimization, but u should be aware abt this behaviour). So it seems that if u assign a final value or a final variable it will work fine.

Another thing - in a mockexam (http://valiveru.tripod.com/java/jvaltest.html) the following declaration is said valid. (which I tested does NOT compile)
int i=10; char c=i;
It will work but with a cast.
Anything wrong?
Thanks
Sanjeet

[This message has been edited by Sanjeet Karamchandani (edited August 19, 2000).]
Hi,
Well, static methods r not overridden and i don't understand what u mean by hiding a method. As far as i know varibles r hidden.
Anyway, overridding has a relation with inheritence, but since static methods r class methods they r not inherited and so can't be overridden. And i think they r neither hidden coz u can always access them as Classname.staticmethod(), so how they r hidden i don't know.
Anything wrong?
Thanks
Sanjeet

[This message has been edited by Sanjeet Karamchandani (edited August 19, 2000).]
Hi,
Well, this problem is already been discussed and someone(Sorry, i don't remember who) had given this explanation and it seems right and works well. Here it is :
In the first case ie Object and String, String is the subclass of Object so the Compiler calls the overloaded version(String version) of the method. But in case of StringBuffer and String there is no relation so the compiler is not sure which method to call so the error.
Thank that somebody
Thanks
Sanjeet

Originally posted by manal:
i also neeed help on this
some1 pls help
manal ...


Hi,
byte b = + 7 ; // compiles fine
BUT
byte b1 = 7 ;
byte b2 = + b1 ; // needs an explicit cast[/B]

Well, thatz right u need to cast it back to byte coz the unary operator( for that matter almost all operators) converts the operand to atleast an int. so if u want a byte cast it.
Thanks
Sanjeet

Hi,
I agree with yanish. he is quite right. The thing is if a new object is to be returned then the objects r not equal otherwise they r.
Now i now it.
Thanks for ur help
Sanjeet
Hi,
Thanks Hema for answering, but u got something wrong.
21) Methods for a Component are:
a) add()
b) setbounds()
c) setVisible()
d) setEnabled()
e) addComponent()
Well method of component include a,b,c,d. Yes add() method is in component that takes a argument of PopupMenu. Plz look in component class again.

import java.awt.*;
import java.applet.*;
public class LayoutApplet extends Applet {
public LayoutApplet ( ) {
setLayout(new BorderLayout());
setFont(new Font("Serif", Font.PLAIN, 14));
add(BorderLayout.NORTH, new Button("North"));
add(BorderLayout.SOUTH, new Button("South"));
add("East", new Button("East"));
add("West", new Button("West"));
add(new Button("Center"));
}
public void init() {
new LayoutApplet();
}
}
This code is working fine and displays five buttons as expected.
Thanks
Sanjeet
Hi Deekasha,
Thanks for answering my questions but there r few problems
17) With respect to User and Daemon threads:
a) Daemon threads can not be destroyed
b) Running User threads prevent a JVM from terminating program
c) Running Daemon threads prevent a Java VM from terminating program
d) Daemon threads can not be grouped together
e) The JVM can terminate program when only daemon threads are running
but what abt option a, is it true or false

18) Primitive type wrapper classes:
a) Allow primitive types to behave as reference types
b) Allow operator overloading to be implemented for primitive numeric types
c) Provide string parsing and conversion methods
d) Provide arithmetic operators such as plus and minus
e) Are provided for all primitive types, including void
your answer was : a c e
-----------------------------------------------------------
but since we do have a wrapper class for void. so option e becomes wrong.
-----------------------------------------------------------
Excuse me but there is a void wrapper class
Thanks
Sanjeet

Hi,
I tried the code and its giving the output as expected
true
true
Thanks
Sanjeet
Hi,
Im going to take the exam next week and i was very confident to do well but after i took abhilash's Quiz i feel the is more to it. Here is a question on String which serprised me. Can anyone explain why its so.
The answer is "Equal" and "Not Equal".
public class AQuestion {
public static void main(String args[]) {
f("String".toString() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
if(" String ".trim() == "String")
System.out.println("Equal");
else
System.out.println("Not Equal");
}
}