Sajan Joseph

Ranch Hand
+ Follow
since Jan 05, 2001
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 Sajan Joseph

Thanks Peter, Daniel Michael,
I am still not sure I have understood this properly. What I have understood is that a protected member can be accessed in a different package subclass only through the sub class reference, not through the superclass reference.
I do not have any actual coding experience. Is this feature used frequently in programming? What advantage does a class developer get in declaring a member as protected? And how does it affect the client who uses it?
SJ
23 years ago

Originally posted by Michael Mendelson:
[B]Sajan, this code worked for me...

I removed the package references for simplicity. I suggest deleting all A.class and B.class files and trying again.
Or, for simplicity's sake, try compling them from the same file.

[This message has been edited by Michael Mendelson (edited January 13, 2001).][/B]


Michael,
I guess for protected access modifier to be tested, you need to put both classes in different packages. What I am not able to understand is why I cannot instantiate an object of class A in class B, and call the protected method a() on the object of A.
Can you clarify that to me .
SJ
23 years ago
I have been doing the exercises in Thinking In Java and came across this one. Can anyone please explain this to me :
package p1;
public class A{// A is in package p1
protected void a(){
System.out.println("Hello");
}
}
package p2;
import p1.*;
public class B extends A{ // B is a sub class of A in another
// package p2

public static void main(String args[]){
A a1=new A();
a1.a();
}
}
The compiler gives me an error message : a() has protected access in class A.
Changing the code in class B to:
A a1=new B() ---> also does not help. Compiler gives the same error message.
The code compiled and ran only when I changed the code :
B a1=new B();
My question is :
As per the defenition of protected, another package subclass can invoke a protected method in its superclass. B is a subclass of A in package p2. Why is it not able to access a() when I had written :
A a1=new A();
a1.a();
OR when I had written :
A a1=new B(); // trying late binding (dynamic method invocation)
a1.a();

Can anybody clarify this to me.
Thank you,
SJ
23 years ago
Hi Everyone,
Peter, I have followed the link and bookmarked it. I shall be coming back to it when I am ready to sink my teeth into OOP concepts and modeling. Thank you very much.
I shall be off Java ranch for a while. I have taken brain bench exams and I must say the results were not dazzling. In Java 1, I scored only 3.77/ 5 and Java2 only 3/5. So it is time to sit down and slog it out for a while. I plan to finish off TIJ and write code and test all of them in the next 15 days.
Networking and Java Beans have to be brushed up and I/O Streams have to be thoroughly overhauled.
I have found that net is a mind boggling resource for anything related to Java. I have downloaded and recorded into CD's about 800MB of Java related material.
The best place to look for tutorials is the java developer connection, just to get a feel of things.
So long every one. Thank you for all the help.
Best wishes,
SJ
23 years ago
What is the advantage of declaring a synchronized method as final? How does it help synchronization?
I do not remember the multiple choice answers given nor do I remember which one I chose.
So far as I could see there was no distinct advantage. It is just a synchronized method which cannot be overridden.
Can anyone shed some light.
SJ
23 years ago

Originally posted by Peter Tran:
Sajan,
If you want to learn inner classes, write a lot more GUI applications using Swing. Understanding inner classes and how they're used in Swing development is almost a requirement. I say almost because you can get away without using inner classes, but your code probably won't be as elegant and as easy to read.
Good luck,
-Peter



Thanks Peter,
I have not gone through the JFC Swing part yet. I was advised that Swing is not used in Web based applications and as such does not figure in dot com interviews. Since getting a job was top priority, I glossed it over. I thought I will finish off the basics before coming to that. But now that you have pointed this out I should have a go at it.
Regards,
SJ

[This message has been edited by Sajan Joseph (edited January 11, 2001).]
23 years ago
I guess Vijay has correctly summarized the difference between Stack and Heap Memory.
In a computer you have different memory areas. There are registers inside the CPU itself where the computation is carried out. You have a cache between the CPU registers and the RAM which is like a buffer. This speeds up memory access. RAM is subdivided into various areas among which you have Stack and Heap. In addition I believe we have separate memory areas to store the static variables - in the static memory area.
In programming languages like C/ C++ one could directly access the stack memory using pointers. Pointers are not allowed in Java. Accessing stack is much faster than the heap. It just requires incrementing and decrementing the stack pointer. (Stack Pointer is one of the registers in the CPU). But creating an object in the heap requiers some over head. So the operation is slow. The advantage that heap offers is : you can create your objects any time you want. You can declare and instantiate an object when ever you feel the need for it. But if you want to use the stack, then you need to declare the variables beforehand. This is because Stack memory is a limited resource and has to be managed carefully. In addition, the objects/ variables created in the stack have to be explicitly destroyed so as to avoid any stack overflow.
SJ
23 years ago
Hi everyone,
I was going through James's mail. Hey James I guess you are a real Object hogger. I need to learn a lot from you. Speaking of Patterns, I recently downloaded Thinking In Patterns from www.bruceeckel.com. Thought I will have a go at it before buying any books on Patterns. I have heard the Patterns book by the Gang of Four mentioned in a number of places. As you said, James, it is the mother of all Pattern books, so it seems at least.
Coming to J2EE, I have got Jason Hunter's Java Servlet Programming. It is a good book, but covers only servlet API 2.0.
As for EJB, I have gone through Enterprise Java Beans from Richard Monson-Haefel. Gosh, it was real hard to plough through the first two chapters. I need to sharpen my teeth before I attempt it again. Both books are published by OReilly and going by indian prices they are very much affordable. But then we have special editions for the subcontinent. And there is a Java conference coming up, here in bombay to be organized by Wrox. Wonder who will sponsor me...
And man, I have not understood inner classes- not the syntax/ semnatics part. But the where to apply part. Does anyone have any suggestions?
What about RMI. Is there a RMI wizard around. I am really fascinated by RMI.
Guess what I gave the brainbench Java 2 exam.. And passed with less than flying colors. The brainbench exam covers right from basics to CORBA/ Servlets/ JSP/ JFC/ and RMI. I was stumped most of the time. Guess I'll take it again after running some of the exam simulators before hand.
SJ
[This message has been edited by Sajan Joseph (edited January 11, 2001).]
23 years ago

Originally posted by Michael Ernest:
It's possible to extrude the appearance of dynamic downcasting out of Java, but it's not natively supported.



Could you please explain me what dynamic down casting is? I have never come across it in Java so far. Is it a feature of some other language. What is its purpose. How does it help.
SJ
23 years ago

Originally posted by Mukti Bajaj:
Hi,
Can someone please explain me this code....according to me it should print both the statements.
As && is true if both the operands are true and will be evaluated first as per precedence order.
And | | is true if either or both the operands are true.
int l = 4;
int m =14;
if(l > 1 && m < 6 | | m > 0 )
System.out.println("Prints");
if(l > 0 && m < 5 | | m >50 )
System.out.println("Doesn't Print");
Thanks.



Hi Mukti,
I ran your program-->It prints 'Print'.
if(l > 1 && m < 6 | | m > 0 )
System.out.println("Prints");
When you run the above if condition, first l>1 is tested and is found to be true. So m>6 is evaluated and is found false. So (l>1 && m<6) is evaluted to false. After that m>0 is evaluated to true. This boolean value is OR'ed with the previous false value and the ultimate result is true.
So your if condition evalutes to true, and the out put is printed 'Print'.
Similarly for the second if condition.
if(l > 0 && m < 5 | | m >50 )
l>0 && m<5 evalutes to false and m>50 also evaluates to false. So your if condition is evaluted to false and it does no output 'Does'nt Print'
As Fred suggested it would be better if you used parenthesis to make the code clearer.
And as such, in your case all the relational conditions are evaluated. The code is not short circuited any where. You could have used & and | to obtain the same result.
SJ

[This message has been edited by Sajan Joseph (edited January 10, 2001).]
23 years ago
Thank You Bill,
I ran your code and this is what I understood :
1. A sub class can create an object of the inner class of its superclass.
2.Super class static innerclass is not instantiated automatically. You have to explicitly create an instance of it, before calling any of its methods.
3. and public static void main() is just like any other method inherited by the subclass. But will not be very useful unless it is overridden by the subclass.
Can you tell me the practical uses of inner classes. Do we ever use them? In fact they seem too complicated. When do we use them. What is the use of static inner classes? I am not very clear on the subject. It would be a great help if you can elucidate. I have gone through TIJ. I have a vague idea. But using an inner class in the classes I write, does not come naturally to me. Nor can I think up any particular use of them.
Thanks and regards,
SJ
23 years ago
Hi Bill, Steve & Kajol,
I started on Java about 3 months back, with the intention of switching over to software. I am an Instrumentation Engr. by profession with some background in C. I went all the way upto EJB's, even downloaded the J2EE and wrote a couple of applications with 4 tiers, using HTML, servlets, EJB, JDBC and and MS Access Database. After that went to attend a couple of interviews, got really grilled and now I am back in the grind. While I was programming servlets and EJB, I hardly came across any of the complicated stuff. Collections, inner classes etc were conspicuous by their abscence.
But now that I have started to prepare for SCJP2, I am having a tough time. You got to know the concepts and syntax of Java and that is where KAM and TIJ helps out.
One thing repeatedly emphasized by my interviewer was OOPS concepts. He was talking about object modeling. And for the first time, I realized that, that is wat I want to do, instead of doing run off the mill web programming particularly since 80% of dotcoms have gone bust. If you can master Object modeling, you can adapt it to any language, perhaps even to C#.
That was the reason why Beginning Java Objets was such a turn on.
Thank you Bill/ Steve for your opinion. I'll have to wait until the book is published here.
And hey James you do'nt sound like a Java newbie. Give me a break. Of course talk doesn't cook rice. so I eat noodles instead.
Regards,
SJ

[This message has been edited by Sajan Joseph (edited January 10, 2001).]
23 years ago

Originally posted by James Baud:
I've scanned "Beginning Java Objects" at the local bookstore and I wish I had this book instead of another Java book I've invested in. But if it's a choice between a free treasure like "Thinking in Java" and something 1/4 of one's salary (I'm tempted to ask is that weekly, monthly ..?), well you get the picture
Speaking for myself, if I could honestly tell myself that I have mastered my TIJ, KAM and Fowler's UML Distilled books then, I don't see a need for any other Language reference.


Aw heck James, I am just an aspiring billionaire waiting to be discovered. :-)
Yes I am going through TIJ at the moment. I have gone through KAM (Khalid A mughal ??) once. I am finding TIJ pretty good. Concise , precise with some really short and simple exercises.
I have heard about UML distilled, but have not got around to buying it. Guess I should finish off TIJ before attempting anything else. But the kind of short passages Jaquie had excerpted in the forum were very catchy.
James, I do not have any practical experience in programming in Java. Though I spend quite some time learning it. Tell me if I would be able to under stand UML distilled? I would greatly value yor opinion.
REgards,
SJ
23 years ago
Hello Pratibha,
Exception handling is a mechanism for handling errors in Java. It offers several advantages such as :
1) It separates the code for handling errors from the actual program code. This makes the program more readlbe and maintainable.
2) In Java exception handling is enforced by the compiler. The programmer is forced to handle any exceptional conditions generated by the program.
In Java all errors/ exceptions are objects. They inherit from a common super class called Throwable. Errors pertain to system errors like memory not available or JVM error which cannet be handled by the programmer under normal circumstances. Exceptions are conditions that occur due to programmer error or some kind of resource unavailability. For example if you are trying to read from a non existent file, then an exceptional condition is generated , which have to be dealt with or if you are trying to divide an integer by zero, then an arithmetic exception occurs which have to be handled.
Java uses the
try{
// some code
}catch(Exception e){
//some error handling code
}finally{
//This code is always executed
}
mechanism to handle exceptional conditions. During exceptional conditions the user can be alerted or a different path of execution can be under taken to solve the problem and avoid abnormal program termination.
I hope I have been able to convey he basic idea of exception handling to you.
Regards,
SJ
[This message has been edited by Sajan Joseph (edited January 08, 2001).]
23 years ago
Never mind Brett. Keep tuning your button.
SJ
23 years ago