Stan Forest

Greenhorn
+ Follow
since Mar 03, 2003
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 Stan Forest

I am attempting the first HTML (form.html with the web.xml file) in Chapter 3 of the Head First book. It opens in a browser but not in Tomcat. The example pages downloaded with Tomcat open normally. Is there a Tomcat installation problem? Any idea what I am doing wrong?
Thanks for the help. I had the classpath set two places and it would not work. It will compile now.
When trying to compile and the system is not finding the javax.servlet package. "package javax.servlet does not exist" is the error message. The location of the servlet-api.jar is set as part of the classpath: c:\Tomcat\common\lib\servlet-api.jar

Any suggestions?
This compiles and prints a value of -1:
System.out.println(Byte.parseByte("-0000001", 2));
The U of M Morris is a liberal arts college. A better degree for Computer Science would be from the U of M Institute of Technology on the Twin Cities (Minneapolis) campus.
Morris is about 160 miles from Minneapolis.
[ July 04, 2003: Message edited by: Stan Forest ]
20 years ago
When adding, subtracting, multiplying and dividing bytes or shorts, the numbers are promoted to int. Because the numbers are promoted to int, the result becomes an int.
Page 458 of the Java Language Specification states: "The class Object is the single root of the class hierarchy. All objects, including
arrays, implement the methods of this class."
An anonymous class instantiates an object. So it is an extension of the Object class.
Where can I find a listing, with explanations, of the J2SE 1.4 error messages?
4. int i = 0;
5. i = i++;
6. System.out.println(i);
The above code prints 0. On line 5 the assignment of 0 is made but after that i does not appear to be incremented. Why?
A byte occupies eight bits
+127 is represented as: 0111 1111
The first digit is a sign, 0 is positive in this case. If the left first digit was a 1, the value would be negative.
128 in 32 bit binary is 0000 0000 0000 0000 0000 0000 1000 0000
when casting to a byte, the left 24 bits are discarded. The remaining is
1000 0000
This is now a byte. Because the first digit is a 1 the value is negative. Convert using two's complement. Twos complement requires inverting and adding 1.
start 1000 0000
invert 0111 1111
add 1
result 1000 0000 = 128 and it was negative = -128

256 is in binary is :
0000 0000 0000 0000 0000 0001 0000 0000
cast to a byte discards the left 24 bits leaving
0000 0000 which is 0
255 is one less than 256 so it is �1
OR
0000 0000 0000 0000 0000 0000 1111 1111
cast to a byte leaves
1111 1111
The first digit is 1 so it is negative so it needs to be converted using two's complement
start 1111 1111
invert 0000 0000
add 1
result 0000 0001 and remember it is negative so it is -1
Can an interface can be instantiated in an anonymous class? Does this code have an instance of an interface?
// From Kathy Sierra's book page 471
interface Cookable {
public void cook();
}
class Food {
Cookable c = new Cookable(){ // instantiates an interface
public void cook() {
System.out.println("Anonymous cookable implementer");
}
};
}
public class Test {
public static void main(String arg[]){
Food f = new Food();
f.c.cook();
}
}
I bring the question up because of Marcus Green's Mock Exam 2 Question 57.
This is a question from Dan's Question Banks.
class A {
static boolean a; // initialized false
static boolean b; // initialized false
static boolean c; // initialized false
public static void main (String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}
}
The output is true, false, false.
Doesn't the && has a higher precedence than the ||? My wrong thinking is that it should be true, true, true. How does the precedence work?