Allen Alchian

Ranch Hand
+ Follow
since Oct 11, 2000
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
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Allen Alchian

Kirill,
If your input mechanism can be simple, then I think the simplest (and fastest for data input) might be to post the full instructions once, at the start of the program, and then after after each user integer-input, just prompt the user with something like the following...
Enter another integer or press Enter to sort and display all data>
This way the user doesn't have to do anything but enter numbers and press enter during the data input phase. When all the numbers have been entered, a simple press of the Enter key with no data will signal the program it's time to sort the data.
If an invalid input is encountered, just display a simple error message then prompt for another input as before. It might look like this...
Invalid input
Enter another integer or press Enter to sort and display all data>
Of course there are as many ways to get input as there are programmers. Do what's best for you...just try to keep it simple.
Good luck.
------------
For Nisha,
You asked if I had "any other not so quick and dirty methods to convert integer values into objects to be added to arrays." No, Nisha, I use the same "quick and dirty" techniques.
Regards,
Allen
16 years ago
Kirill,
Nisha's response gave you a quick-and-dirty example of wrapping an int into an Integer object. I'll assume you follow how that's done so I won't dwell on wrapping ints into Integer objects, unless you ask for more on the topic.
You wrote that you will get integers from "the user." This makes me wonder precisely how the user will provide those numbers. If the user inputs the numbers while the program runs, then I assume you are aware that you are actually dealing with Strings and not int values, and that you'll have to convert each String to an Integer object. Shall I assume you have a handle on this part of the problem?
Another aspect of the problem that you need to deal with is the fact that Vectors store objects of the Object class. Consequenly you will have to do some casting of each Object to an Integer when you manipulate the vector objects. Are you aware of this, and are you able to do this part of the problem?
If you haven't been exposed to the Java API Specification web site, I strongly encourage you to visit it and start getting familiar with it. It is a bit overwhelming at first, but with some experience you will eventually get the hang of the organization and how to use the information. Visit http://java.sun.com/j2se/1.3/docs/api/index.html
At that address three windows appear, one in the upper left, one in the lower left, and one on the right.
Let's use class Vector as our first excuse to visit the site. When it first loads, all Classes are displayed by default, in the bottom left window. You use the top left window to select the Package you want to view. The bottom left window will display the classes in the Package you select in the top left window. Scroll through the list of classes (bottom left window) to find the one you're interested in and when you click on a class, it's specification will show in the large right window.
Being sure you have All Classes selected in the top left window, scroll throught the list in the bottom left window until you find Vector. Click it and you'll see the description of Class Vector appear in the large right window. A lot of information is presented...it'll overwhelm you if you've never done this before. But take the time to learn how it's organized. I'd suggest printing it...it'll take several pages, but I think it's worth the investment of paper and ink to help you get the feel of the kind of information and how it's presented.
First you'll see a general description of the class. You'll see that the Vector class comes from (inherited from) the java.lang.Object class. This is an important point because this is the basis for all Vector elements being of class Object. Scroll down a bit and you'll see a "Field Summary", a "Constructor Summary" and a "Method Summary". They all contain very useful information about the Vector class that you'll be using to solve your problem.
At this point, I'll terminate my response because I've gotten long-winded. What aspects of your problem do you need help on now?
Allen
16 years ago
Kirill
Perhaps you should break the problem into various pieces, and solve each piece. For example, do you know how to create a vector?
Do you know how to wrap an integer into an Integer object?
Do you know how to populate the vector?
Do you know how to move the elements of the vector around (i.e. change their relative position)?
Do you have the code for any sorting algorithm?
Is your answer "no" to all of these?
Allen
16 years ago
I first started Java programming last September...had never programmed in an OOP language.
Like you I purchased "Core Java 2, Vol 1". I, too, needed "something better". Ultimately I purchased about a half dozen other books. These included the Deitel book; "just Java" by van der Linden; "Thinking in Java" by Eckel; and "The Java Tutorial Second Edition" by Campione/Walrath--all touted by Java Ranch. But none were as valuable to me as a beginner as "Teach Yourself Java" by O'Neil (Osborne/McGraw-Hill 1999)...$30. The book focuses on applications, rather than mixing up applications and applets as does Deitel. And it provides many, many examples. Further, and most uniquely, along with giving exercises (problems), it provides solutions to those exercises. It is purely for beginners. The other books are also good, but I definitely used O'Neil's book the most.
By the way, I also found the Java Ranch Cattle Drive very helpful for improving my programming style. Good luck in your programming education.
Allen
16 years ago
You can invoke another constructor of the class, as follows:

You can refer to the current object, as follows:

Hope this helps.
16 years ago
I think you can survive without it. I did about half the Cattle Drive assignments and used other books more than I used "Just Java." (Actually, I did all the assignments...but only the first four were submitted for evaluation.)
I purchased the book when I started the Cattle Drive; I could have done the assignments without it. The book's okay, but I personally would suggest that you give the Cattle Drive a try before you spend more money for another book. You can always buy the book later if you decide you want it.
Allen
[This message has been edited by Allen Alchian (edited April 25, 2001).]
16 years ago
I believe what is meant is that accessing a single element in an array requires constant time regardless of which element you are accessing, whereas accessing a single element in a linked list requires linear time. In other words, if you want to access the 100th item in the array, the computer would go directly to the 100th item and get it. However with a linked list, the computer would have to go to the first item, then the second item, then the third item, etc, until it got to the 100th item...hence the "linear" access time for the linked list.
In your test, you accessed the 100th item of the array after accessing all of the previous items first...hence the time savings of an array data structure was eliminated.
Allen
16 years ago
I happen to have JBuilder (version 3).
The computer I use is a 500 MHz machine (128M RAM).
I'm not a software professional...mostly just a computer science student or part-time programmer.
With that framework established, here's my perspective:
I am rather surprised at how long JBuilder takes to load on my computer. Of course you only load it once each time you use it (theoretically). Bottom line...yes, it is a big program.
The above comments are basically on the mark and I don't disagree with them. I don't like to write my programs with JBuilder; I don't like the code it produces and when I write my own code I don't find the JBuilder's built-in editor to be particularly "user-friendly".
I much prefer to write my code in TextPad (a wonderful shareware program that costs only $27 register...and worth every cent). Although I can compile java programs within TextPad, it isn't designed for extensive debugging. So, when I need to do some "heavy-duty" debugging of my Java programs, that's about the only time I pull out the JBuilder so I can step through the code and watch the variables, etc. Beyond that, I stay out of JBuilder (or any other IDE for that matter).
I've been rather surprised (disappointed) at how often JBuilder has locked up on my computer. Or is it just so slow that I am mistakenly thinking it's locked up. Whatever. There is now a JBuilder 4. I can only assume it is even "bigger." Hopefully it is more reliable. But I'm not running out to buy it just yet.
Hope this helps.
Allen
[This message has been edited by Allen Alchian (edited February 26, 2001).]
16 years ago
But of course!
I knew that....just sorta forgot. Thanks for replying, Graeme.
Allen
[This message has been edited by Allen Alchian (edited February 24, 2001).]
16 years ago
I have integer variables (primitive type int) and want to use their values to create a character (primitive type char) based on unicode value of the integer.
For example...
int i = 65;
How do I get the character A out of the value of variable i?
I can't figure a way to make the conversion. (Mind block? ) Any suggestions?
Thanks.
16 years ago
I just want to "piggy-back" on Angela's suggestion. The JavaRanch Cattle Drive sounds to me like it is just what you need at the moment. I started out learning Java on my own last September with the typical "Teach Yourself..." books. Certainly those are useful, but there's nothing like having someone look over your shoulder to give constructive criticism. I didn' have that until I stumbled into the JavaRanch one day and took a ride with the Cattle Drive. It made a big difference for me. I highly encourage you try it, but look out for all the dust and dirt (not to mention the "nit-pics")!
16 years ago
Brett
Local variables. These are declared within a method.
Member variables. Variables declared within the class body but outside of any methods or constructors are considered Member variables. I believe these are also sometimes referred to as "Class variables." (Someone will correct me if I'm wrong.)
Static variables. These are member variables, but have the "static" declaration with them which means that you can access the variable without making an instance of the class. Also, if there are instances of the class (i.e. objects) the individual objects do not have their own copy of the static variable...only one copy of the static variable is maintained.
Instance variables. These are member variables, but other than that, they are essentially the opposite of Static variables...you can only access them through objects of the class; each object has its own copy of the class Instance variables.
Reference variable. A variable that simply holds a memory address because the variable refers to an object rather than a primitive data type (eg: int, byte, char, boolean, double, etc). Most variables are probably Reference variables.
Please note that this list is probably not exhaustive, and the variable types listed above are not necessarily mutually exculusive.
Allen
[This message has been edited by Allen Alchian (edited February 18, 2001).]
16 years ago
Yeah, Randall, you're right. I guess I read the question just too fast. I don't know the answer to Pho's question; it's a good question. I hope someone knows the answer 'cause I'd like to know, too.
Allen
16 years ago
Mary Ellen
Here is a shot at what I understood you are looking for. I cheated by giving each person the same name and status, just to get data into the array. I assume you can figure out how to fix that part. Probably can use some other refinements, but this will hopefully help you understand the array issue. Hope this helps.
Allen

16 years ago
You need to read the postings at this thread. It gives an excellent response by Stephanie Grasson. http://www.javaranch.com/ubb/Forum33/HTML/000601.html
Allen
16 years ago