Larry Jones

+ Follow
since Oct 22, 2002
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Larry Jones

Here's a good starting point:
FAQ Page
[ April 26, 2003: Message edited by: Larry Jones ]
An integer has thirty-two bits. It uses two's compliment notation where the leftmost bit is the signed bit. The smallest number an integer can represent is a "1" in the sign bit and the rest zeros:
The largest number an integer can represent:
So I guess the shortcut is knowing the number of bits the number type can hold. For example, I know a byte has eight bits, so I know Byte.MIN_VALUE is:
And Byte.MAX_VALUE is:

Dan C. has a good tutorial on this and also changing them to Hex:
Dan's Tutorial
When you declare a variable you can assign it a value. It is the special circumstance of its declaration that allows you to do that outside a method. But you cannot start manipulating that value OUTSIDE of a method or constructor.

here the variable "a" has been declared and initialized to the value 0.
when you do this:

You are trying to assign another value to "a"; this can only be done in a method or a constructor.
Regarding the errors: It looks like the compiler thinks this may be an attempt at an inner class, or another variable.
Maybe this type of thinking will help:
This is one of the great advantages of OOD. If you were not able to make a generalized class and extend it, then you would have to create all these different method names that did essentially the same thing: You would have to have a "carDrive()", "truckDrive", "segwayDrive", etc.
With OO, no matter what type of Vehicle that is on the other end of that Vehicle reference, all you have to do is call the drive() method, and that subclass of Vehicle knows what to do. So, for example, if you didn't know there was a Car on the other end of that Vehicle reference, it wouldn't have mattered: The Car still knew how to drive itself.
To address some more concrete issues:

That one line that reads v = c. The way I try to remember it, is ok, "c" is coverted to a "v" so that it can fit into a "v." "c" CAN be converted to a "v" because in actuality "c" is just a "v" with some add-ons.

Here it seems like you are thinking of object references as if they were primitive data types. What happens in the "v = c" line is that the address of the object that c is pointing to is being given to v, so now they point to the same object. "c" is not being converted to a "v", "c" is actually the same as it was before the assignment; the difference is, "v" is now pointing to what "c" is pointing to: The Car.
This is like what Anupam was saying.
[ April 21, 2003: Message edited by: Larry Jones ]

My compiler says the errors are at lines 4 and 6. (As oppossed to 4 and 5). There's a compiler error at line 4 because the String class doesn't have an append() method. And there's compiler error at line 6 because the concat() method doesn't take a StringBuffer object.
But to get to what I think you were asking about: Those String methods, like trim() return newly constructed String objects. You can assign them to a reference:

String myNewString = s.trim();
or not:
If the String object is not assigned to a new reference, then it is lost, and the string in the s String object stays the same.
StringBuffer methods DO change the value of their object, so there is no need to tie the new object to a reference, as there is with String objects.
Thank you everyone for your responses. I understand what is going on in the code now, but I would like to ask one more question: Can someone give me a simple example of a && operator being evaluated before the || operator? That is, in what situation does the && operator show it has higher precedence? I've tried many little programs, but the results seem to indicate that || and && have the same precedence and are evaluated from left to right.
16 years ago
Thanks Doco, but it is those short circut operators and the fact that the variable assignment statements may or may not occur, which gives the opportunity for some of them to remain false.
For example
boolean a;
boolean b;
if((a = true) || (b = true)){}
System.out.println( a + "," + b);
This prints: true,false
But back to my original example: I can't understand what is going on in the order of precedence.
Why does this happen:
( (a = true) || (b = true) ) && (c = true);
and not this:
(a = true) || ( (b = true) && (c = true) );
[ April 07, 2003: Message edited by: Larry Jones ]
[ April 07, 2003: Message edited by: Larry Jones ]
16 years ago

This prints true,false,false
I'm stuck thinking it should print true,true,false
Since the '&&' has precedence over the '||' shouldn't they be evaluated first?
It seems (b && c) should evaluate first. b==true, so it would short-circut leaving c==false. This would leave (a || true). The left side would evaluate first, also short circuting. 'a' would be set to true, resulting in: true,true,false
Why doesn't the && seem to have precedence?
Thank you
16 years ago
Marcus Green
I know this guy's mocks still have 1.2 related questions.
Foo dosen't have-a Bar.
In the code below, Foo has a Bar:

Baz, which extends Foo, has a Bar. But in OO terms, Foo does not have-a Bar.
For a has-a relationship, either a class, or a superclass must have a member that is a reference to the object.
[ March 13, 2003: Message edited by: Larry Jones ]
Thanks for your input everyone.
16 years ago
This is something that I have been thinking about for awhile. Let's say I develop a java application that is not an applet, and not a servlet, but a standalone java application. If I am in a client-server environment, can that application be put on a server and accessed by all the client computers? Or does it have to be installed separately on each computer I want it to run on? Is this what is meant by an 'application server'? Or is a server that runs servlets or Coldfusion an application server?
And a follow up: If I am in a client-server environment running win2k server, can a Microsoft application such as Word be put on that server and be accessed by all the client computers? Or does it have to be installed separately on all the client computers?
Thank you for any responses.
16 years ago
Hello, I have a simple program that queries an Access database. I connect to the database using JDBC DBC. When I install this program I open a system data source in ODBC, and select the microsoft access driver. It has always worked fine. Today I tried to install it on a Windows 98 machine, and when I was setting up the datasource in ODBC, there was no microsoft access driver (*.mdb), but only an Access 97 driver. I selected this driver but the program did not work. The database that the program queries was created with Access 2000. Any ideas? Thank you for any responses.
This site has an online test that you can take for free. The test is 25 questions.
16 years ago
If you're talking about a JList, I think this is what you're looking for:
String[] data = {"one", "two", "three", "four"};
JList dataList = new JList(data);
dataList.setSelectedIndex(1); // selects "two"

//Gets the item from the list
//You must cast it to a String
String item = (String)dataList.getSelectedValue();
if (item.equals("two"))
System.out.println(item);//prints two
16 years ago