This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!

Tony Jackson

Ranch Hand
+ Follow
since Feb 23, 2001
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 Tony Jackson

William,

Do you have the current directory (.) in your classpath? Maybe at work you do but at home it is missing?

That probably would not account for all your problems, but it is worth checking.

PATH: used by the operating system to find executables (particularly javac.exe and java.exe, which are the java compiler and the java runtime, respecively)

CLASSPATH: used by the Java VM to find classes. Classes that are part of standard Java (such as java.lang.System and java.util.Vector) don't have to be added to the CLASSPATH, as Java VM inherently knows how to find them). But if you have code in a class that calls another class (creates an object, or calls a method) then you need to have that other class in your CLASSPATH.

One thing about classpath that seems to confuse some people is that while you can add directories to your classpath, you also can add jar files. Since a jar file is an archive of directories, it is considered a directory, so you must put the jar file in your classpath, not just the directory where the jar file is located.

That means if you have 10 jar files in the same directory you must add all ten of them to your classpath.

Tony
16 years ago
Hello Jose,

1. Why packages:
Because you and I may both create a class with the same name. For example, Element or Document. Packages give us, and the people who use our classes, a way to distinguish between the classes.
When you specify a class using the package name AND the class name, you are said to be using the "fully qualified" class name. As Anthony mentioned, "java.util.Date" is one way to specify the fully qualified name of that particular class, and that is a different class from "java.sql.Date" even though the class names are both "Date".

2. You probably already know how to use classes that are in packages. For example, the Vector class is in the package java.util and you can specify a Vector two ways:

a: put an import statement at the top of the file:

import java.util.Vector;
...

Vector v = new Vector();

b: specify the fully qualified name:

java.util.Vector v = new java.util.Vector();

3. What if you are defining your own class and you want to put it in a package? Then you need to do two things:
a: put the package statement as the first line of your code (only comments or blank lines can come before a package statement)
b: create a folder structure that mirrors the package statement

For example, if your package is com.josenavarro.coolapp and your class is named MyApp then you would have this folder structure:

com (folder)
josenavarro (folder inside com)
coolapp (folder inside josenavarro)
MyApp.class (compiled java class inside coolapp folder)

If you are using an IDE then it might create the folder structure for you, but if you are using the Java SDK then you need to compile the class and then create the folder structure and put the class in the appropriate place.

4. Once you have created the folder structure you can use the jar utility to create a jar file. This is optional but makes sense if you have lots of classes in your folder structure.

5. You probably noticed that a lot of package names look like www addresses, but backwards. The reason for this is that companies (and people) who create classes want to ensure that their package name is unique (so their classes don't potentially conflict with someone else's) and one way to get a unique package name is to take your registered domain and use it as the start of all your package names.

So if your company domain is mycompany.com and you have some customer projects and some internal projects, you might consider package names such as:

com.mycompany.cust.customera.project1
com.mycompany.internal.database.dbproject

etc.

Tony
16 years ago
Thomas,
Thanks for that.

Tony
16 years ago
Hi,

I'm curious as to what the different member status designations are and the criteria for them. I went from greenhorn to ranch hand after my 30th post, so that seems to be the status for ranch hand; but i don't know what the other designations are.

Thanks,
Tony
16 years ago
Thanks Ernest.

Tony
16 years ago
Hi Jay,

This seems wierd to me. I would think that an IDE would use reflection to determine the fields and methods in a particular object, but I just tried using reflection on a HashMap object to no avail.

So in the following code, the length of classes and fields arrays are both zero:



The fact that there are no fields makes me think that there shouldn't be anything visible to the IDE inside a HashMap object.

Can anyone add anything to this?

Tony
16 years ago
Jigar,

You are right. I went to the source (The Java Language Specification, Second Edition) and on page 91, in Section 6.4.2, "The Members of a Class Type", it says:

If the method not inherited is abstract, then the new declaration is said to implement it; if the method not inherited is not abstract, then the new declaration is said to override it.

Tony
16 years ago
Chris,

Maybe i'm missing something here, but it looks like you left out the return type:
public getBlobAddNameBean(String x);
should be
public void getBlobAddNameBean...

also,
is this an abstract class? If so, you omitted the word abstract from the class declaration. If it is not an abstract class, then you cannot have the semicolon at the end of the method signature above; instead you need curly braces and a class definition.

Tony
16 years ago
Shilong,

It sounds like you want to store a number of things in each hashtable entry.

First things first. Here is some sample code that creates a Hashtable, puts in a couple of entries, and then retrieves those entries:



OK, now what if you have multiple grades per student? You can store an array in the Hashtable for each entry, instead of storing a single Integer object:



I hope that helps.

Tony
[ June 21, 2004: Message edited by: Tony Jackson ]
16 years ago
J Js,

I'm not sure what you mean. You want a way to store dates? A way to enter dates? A way to create functions (methods) that act on dates? Are you looking for a method that can take a String entered (perhaps by a user on the keyboard) and convert it to a Date object?

Java has a Date class (java.util.Date) that is used to create Date objects. These objects represent specific points in time (ie, date and time). You can create a Date object using one of the class constructors and then you can use the Calendar class to work with the dates. The Calendar class and the GregorianCalendar classes are useful. In fact, the javadocs for GregorianCalendar has an informative code snippet which shows how you can work with dates. You should look at the javadocs for GregorianCalendar for more info.

Tony
16 years ago
Bikash,

To clarify a question: you said "...if i changed the value of str="def"..."

you cannot change a String. So if you say str="def", what is happening is that the reference str now points to a different string. If "def" was not already in the string pool, it will be created; but now str points to it. You cannot change a string.

Tony
16 years ago
Fanny,

1. c cannot be an Iterator, since Iterator does not have a removeAll method.

2. Collections.singleton(Object o) returns a Set with only one object in it. So if c is a Set, then c.removeAll(Collections.singleton(e)) returns a Set which does not include the object e.

Tony
16 years ago
Hi,

I'm looking for some ant tutorials, if anyone has any suggestions? Yes, i have looked on ant.apache.org, and the manual there is not doing it for me. But it doesn't seem complex enough to warrant buying a book. Any thoughts or suggestions? Thanks.

Tony
[ May 21, 2004: Message edited by: Tony Jackson ]
16 years ago
Hi Bhuvana,

This sounds like maybe a programming assignment, so i will give you a couple ideas but won't give you the code.

You are on the right track using substring. if you know that a comma is at position p in String s, then you can use s.substring(p+1) to give you the part of the String that is to the right of the comma.

You can use the indexOf method to find out the position of the next comma.

Combine these in a loop and you have a powerful way to loop through the string.

You can then do a couple of things: You can "tokenize" the string as mentioned by Ashok. That means creating an array (or List) and putting the separate elements in the array and then you can loop through it easily.

Or if you are simply looking for an item (such as the first occurance of the number "17" then you can stop when (if) you find it.

It can be confusing at first in figuring out how to put the loop together. What i suggest is that you write down, in words, the behavior of the program/loop. In other words, how would YOU find the first occurance of the number "17" in such a list? What do your eyes and mind do as you are looking for it? you start at the beginning, look for a 17 that is between 2 commas, etc.

Good luck,
Tony
16 years ago
If a class is not abstract and you declare a method as abstract, it won't compile.

from the compiler:

C:\a\Test.java:1: Test is not abstract and does not override abstract method abstractMethod() in Test
public class Test {
^
1 error

Tony
16 years ago