Sam Aran

Greenhorn
+ Follow
since Sep 06, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Sam Aran

Don't.

Don't look for this.

This is not needed to be known by you. At all. Ever.

You are falling into the implementation trap. You may find which classes call this on Tomcat, on X, on Y, on Z, etc. But what about Tomcat 5 vs. 6? What about X1 vs X2.5?

The basics of what you need to know for your container is what servlet specification it implements and that is places elements found in the web.xml file in the appropriate order. You can write simple test cases to verify this.

It doesn't matter what calls the Servlet classes you specify, as long as you verify that they DO GET CALLED. You are trying to find out increasingly irrelevant information. There is a reason you have a container in the first place, so you don't have to worry about all this start up code and threading...you just worry that your code will function properly once you rest easy that it is indeed being called.
16 years ago

Originally posted by ARIJIT DARIPA:
static methods are inherited


That's not an instance of inheritance, that's an instance of accessibility. Since both classes are in the same package, the static method is available to the Child subclass. Since Child is castable to Parent(), when the StaticMeth method is attempted to be invoked, the compiler first checks for a method of Child that matches it. It does not find that, so it checks the super class. It does find a method, but it is static. So, it uses the static shortcut. Saying c1.StaticMeth is equivalent to ((Parent)c1).StaticMeth(); This shortcut is then taken one step further and the result is Parent.StaticMeth(); Only non-static methods and variables are inherited, statics by definition cannot be inherited because they are only defined for the class or interface they are declared in. Just because you can access them from this sort of shortcut doesn't change this, it is a convienience, nothing more.

Originally posted by kunal dabir:
Hi,

Please refer to the 11th Question in Self Test of Chapter 2:


Shouldn't the Answer be 'Compilation Error', as 'y' is a static variable and hence wont be inherited in the 'Minor' class which is using it in the default constructor?




[ September 08, 2008: Message edited by: Samus Aran ]

Here is the previous code, with "this" added to where the instance variables are used. Note that g, since a is not a parameter to the method, actually alters the instance variable a, resulting in "1" "0" (b is unchanged, g uses its own copy) and 1 (c is passed as the reference to the array, and the actual int stored at 0 is set to 1 in g()).
I don't know what "rank" is, so I'm going to use a general collection for this, but you'll need to use a specific one for "rank" if you want to get rid of the inevitable warning.

I'm assuming your cards *are* in a collection. Since I'm using general collections, I'll use a standard for loop, if you use generics, you can convert it to enhanced.



If three or more cards have the same rank, a rank entry will be inserted for the first one, but not the two duplicates, so you compare it to the total number of possible choices (independent ranks) minus the two duplicates. You needed "at least", so if it is less than that (for instance, there are 4 cards with the same rank), the set will have less and this will be true.
16 years ago
Look for KompoZer, it's pretty decent, though it has its bugs, these bugs probably won't hinder your efforts.
16 years ago
Also, don't use Vector, because Vector is ArrayList's retarded older brother. Use an ArrayList instead, always (even if you need some synchronization, it is not worth the hit of all of the Vector methods being synchronized).
16 years ago

Originally posted by shaf maff:
Here is the 500 error:

java.lang.NullPointerException
Get.doGet(Get.java:140)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

This is line 140:

for(MailSession mail : test) {

BTW, what does the note/warning mean and why ignore it ?



.


What this suggests to me is that for some reason the session is not returning a List (that is, the attribute returned is null, because mail being null would not throw an NPE) Test is probably null. This may be because it is a different Session object somehow. Your best bet is to store some kind of identifier value into the session (as a string) and then look for this value at this line with a debugger. If that value is not a Session attribute, then you do indeed have a different session for the current request and as such may not have the information you require.

As for the warnings, the reason you *have* to ignore this is that the Servlet API has been here for awhile, especially before the Java 5 change. Therefore, it is backwards compatible (for the most part) with previous versions. getAttribute returns Object, which is what it has to return, naturally (you can store anything) but the compiler now warns you that you're doing a potentially unsafe cast (casting it to your List<special> type) because the only safe cast in that situation is a method defined as returning (directly) a List<special> instance.

The other one is a SerializableUID warning, which Eclipse can solve instantly for you (add default serializable id) which creates a private static final long serialVersionUID = 1L; This is because your class implements the Serializable interface, which recommends that a class provide an identifier for its version when being serialized (otherwise, this will be generated by the JVM).
16 years ago

Originally posted by gopala krishna muvvala:
I am getting problem in this code

1 String from[];
2 int count=0;
3 Scanner s=new Scanner(System.in());
4 System.out.println("Enter stings..");
5 from[count]=s.nextLine();
6 count++;
I am geting error in line 5 that is Nullpointer Exception...
Why is ther any wrong in this code......?



It's probably better to use an ArrayList. Since you're using Scanner, I'm assuming you're running at least Java 5.

16 years ago
I'd like to point out that some parts of this chapter are blatently incorrect:
[quote name="Page 336"]
A switch's expression must evaluate to a char, byte, short, int, or, as of Java 6, an enum


Enum switching has been available since Java 5. This error is also made on the certification summary section.

The following has also been available since Java 5:
[quote name="Page 345"]
As of Java 6, the for loop took on a second structure

So called "enhanced" for loops have been available since Java 5. This mistake is also on the certification summary.

A question: is there an official errata page for this book?
Are you using Sun's Java compiler? I'm using the Java 6 compiler (windows 32-bit) and I'm not having any problems compiling your code. I copied the code verbatim, and even somewhat-autogenerated another version using a different package through eclipse (called test for the package, and I can compile it fine).

On the command line, I had to use this line to compile both files, though:


Does the code compile with an IDE such as netbeans or eclipse? I've found that generally it's easier to check compilation with an IDE...