 |
 |
Index ‹ java-programmer
|
- Previous
- 1
- What will be your DAO design ?For the following tables, which is a general rdbms design, what classes will
you create for accessing these tables ?
Table 1 : Group
group_id (PK)
group_desc
Table 2 : User
user_id (PK)
user_name
Table 3 : Group_User
group_id (FK)
user_id (FK)
- 1
- Send ARPHello everyone,
I want to verify if an IP is in my local net or not.
If I send an ARP request and get a MAC from that then the IP is in the
local net.
That's why I need to send an ARP request in Java under Windows XP and
NT.
Can anyone tell my how this is done?
Doing this native with the Windows iphlpapi.dll seems to be a bit
complex.
Any ideas for any easy way?
Thanks.
bye bembi
- 2
- Arrays - component type vs Element typeCan anyone explain to me the difference between an element type and a
component type?
In the java literature, arrays are said to have component types, whereas
collections from the Collections Framework are said to have an element
type.
http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html
states:
> The *component type* of an array may itself be an array type. The components of
> such an array may contain references to subarrays. If, starting from any
> array type, one considers its component type, and then (if that is also an
> array type) the component type of that type, and so on, eventually one must
> reach a component type that is not an array type; this is called the *element
> type* of the original array, and the components at this level of the data
> structure are called the elements of the original array.
Reading that - I thought I'd 'got' the difference, but then in 10.1 (a
para later) the terms seem to used synonomously!
> An array type is written as the name of an *element type* followed by some
> number of empty pairs of square brackets []. The number of bracket pairs
> indicates the depth of array nesting. An array's length is not part of its
> type.
> The element type of an array may be any type, whether primitive or reference.
> In particular:
>
> € Arrays with an interface type as the *component type* are allowed. The
> elements of such an array may have as their value a null reference or
> instances of any type that implements the interface.
> € Arrays with an abstract class type as the *component type* are allowed.
> The elements of such an array may have as their value a null reference or
> instances of any subclass of the abstract class that is not itself
> abstract.
When describing collections from the Collections framework there is
never any of this ambiguity/distinction - it is always "element type",
even when talking about a collection whose elements are themselves
collections.
Am I missing a "big idea"?
Any thoughts greatly appreciated.
Rob
email***@***.com
- 2
- 9?. Steps To Improve Your FlyingThere are many things that you can do when you fly to make yourself a
safer and better pilot. Too many pilots get careless and stop doing
fundamental things that could save their lives. Here are some simple
things that you can do to improve your flying.
1. Use your rudder pedals.
It seems simple, right? Well, too many people neglect to get in the
good habit of using them. Use them during taxi, takeoff, climbs,
cruise, maneuvers, descents, and landing. Get the picture - Use them
all the time.
You can know exactly how much to use them during flight by looking at
the slip/skid indicator. That is the ball of the turn coordinator. As
long as the ball is centered between the lines, you are using the
right amount of rudder. If the ball is outside the lines, add rudder
in the direction that the ball is located.
For instance, if the ball is to the right, add right rudder. An easy
way to remember this is to "Step on the ball." Add enough pressure to
re-center the ball.
There are a lot of things happening when you are airborne. Correctly
using your rudder will make you a better pilot, keep your passengers
happy, and show your piloting professionalism (something you need to
have, even if you are not a professional pilot). Remember, step on the
ball.
2. Use Your Checklist
As you are flying, make sure that you use your checklist for each
portion of the flight. There are checklists for everything from
preflight to securing the airplane. Most airplanes have a checklist in
the owner's manual that you can use during your flights. Also, when
you learn to fly most flight schools have checklists that are
available for their students.
But checklists aren't put there to look pretty. Your job is to use
them. If you get in the habit of using one each flight, you will be
that much safer. It's not going to do you any good in your flight bag.
Even if you know the items by heart, still double check yourself
anyway.
Another thing, if you need to add something personal to your checklist
(like don't forget your sunglasses, or turn off your cell phone so the
battery won't run down as it searches for a signal in flight) do this
as well. As long as you have all the required items included, add any
that will help you personally during your flight.
3. G.U.M.P.S.
Whether you use G.U.M.P.S. as your landing checklist or not, get in
the habit of using a memorized checklist for your return to earth. In
a complex airplane, Gumps is; Gas, Undercarriage, Mixture, Propeller,
and Seatbelts. In a non-complex airplane, Gumps could be; Gas,
Undercarriage, Mixture, Power, and Seatbelts. Of course you don't
actually have to lower your gear on a fixed gear plane, but it is best
to remind yourself anyway. That way, when you do transfer to a
retractable gear airplane, you won't have to add anything to your
checklist. This also happens to be one of the most important checklist
items of the whole flight. So you will already be in the habit of
checking your landing gear when you get to the point where it really
matters.
4. Weight and Balance
Never ever forget to precisely calculate your weight and balance for
each flight. Too many people have gotten lazy and careless, and have
added extra weight in the form of passengers or cargo to their
airplanes, thinking that everything is ok. Isn't there room for error
- a little safety cushion, if you will - in the maximum useful load?
Why would you even want to know? If you take this attitude with your
flying, you are putting yourself and your passengers in a very
dangerous situation. Never operate out of the manufacturer's set
limitations for your airplane. They are there for a reason; to keep
you safe!
5. T.O.L.D.
Takeoff and Landing Data should be calculated for every flight as
well. Make sure that you are very familiar with all of the runways of
intended use and their lengths and widths. If it is not something that
you or your airplane can handle, don't make the flight. Don't get in
the habit of assuming that just because you are in a Cessna 172 that
every landing strip is suitable for your flight. Calculate your
takeoff and landing distances for each flight, taking into
consideration the density altitude and aircraft performance.
6. Appropriate Radio Calls
One flying safety item that can easily be performed is making sure
that you make your radio calls at the appropriate time. Whether you
are flying out of a towered or uncontrolled airport, be professional
with your radio calls. One common error is made at uncontrolled
airports, when after an airplane lands, the pilot calls clear of the
runway while part or all of the airplane is on the runway side of the
hold short line. This is dangerous! What if your airplane malfunctions
and you are stuck on the runway and another airplane thinks it's safe
to land? This is a hazardous situation that can easily be avoided. At
non-towered airports, it's better to not make any radio call at all,
than to make a dangerous one. Get it right!
7. Complete Runup
You have done a complete preflight inspection and are now ready to
takeoff. Make sure you do a complete engine runup as well. Check every
aircraft system while you are still on the ground before you get in
the air. Determine that all of your radios, comm and nav are
functioning. Check your vacuum and electric gyros. Check your flight
controls and your engine gauges. Know that when you take off, you are
as safe as you can be. There is no reason to rush through your runup.
8. Situational Awareness
Situational awareness is when you know exactly what is happening with
your flight and with what is going on around you. On the ground, you
need to make sure that you are aware of other airplanes that are
taxiing and using the runway. In the air, use the radio and your eyes
to know exactly where other airplanes are in relation to you as well
as their intentions. But situational awareness is not just limited to
knowing where other airplanes are. You also need to know exactly what
is happening with your airplane, the weather, airspace, the winds,
your location, what you would do in an emergency, etc. Regardless of
whether you are flying cross country or local, for fun or for
training, don't assume everything is alright. Know what is happening
around you.
9. Fly the plane from engine start to shutdown
When it comes to flying, make sure that you are maintaining vigilance
at all times in the airplane. Too many times pilots zone out at some
point in the flight. For many pilots, that time is before takeoff and
after landing. Make sure that even when you are on the ground, you are
flying the airplane. Keep a watchful eye out for other aircraft and
don't rely on the tower to separate ground traffic. Position your
flight controls so that you have the proper crosswind correction,
regardless of the wind speed. Even if the wind is calm, look at the
wind sock and taxi as if the wind is really blowing in the direction
indicated by the sock. Although you are on the ground, your control
surfaces are still somewhat effective. Treat them as if your safety
depends on their position.
9?. Have Fun
Even though it sounds simple, keep your flying fun. When you are in
the air, you are living a dream. Don't forget it!
http://cncarrental.cn/html/goodspeech/20060924/633.html
- 3
- History of objects?Hi
a relatively complex project I am working on now has a need for
"versioning". I mean, we have a system for administration of data (creating
and updating) in a database, and this data needs to be saved as separate
versions each time it is updated - a lot like a CVS.
The data is in the main "bridges", which have lots of data (name, location,
height etc), and lots of related data: persons (controller, supervisor);
tasks to be performed...
It should for example be possible for a user to view a "bridge" as it looked
on a certain date in the past, with all its related data (as they also were
at that date).
Does anyone have some good ideas about how we can save a history of versions
of all our objects? Where can I start to look for good ideas? Could we use
CVS via some sort of java api?
Thanks,
Peter
- 3
- Can I restrict permissions at runtime?I have an editor application that I've writen that needs to read and
write XML files to disk. I'd like to extend this program by allowing
users to extend my editor by plugging in custom code they compile using
certain interfaces. My editor will call their code to gain use of
their functions.
However, this plugin code is untrusted, and I don't want it to access
the filesystem or network. Is there some way I can create a sandbox
within my program in which I can run this custom code and be sure that
it cannot do things like write to the filesystem? Perhaps create a
separate thread with special restricted permissions?
Mark McKay
- 3
- 4
- writing java daemon server: start and stopDear everyone,
I am trying to write a server program to do some monitoring.
I am using Windows 2000 platform.
I've seen that there is some server program can start server by
specifying command like "server start" and stop it like "server stop".
I am wondering how to do it in java language since java is running in
the JVM.
1. Is it prossible to send signal to kill the process just like c lang
?
2. Do java have process ?
3. How about if java thread can be killed by those deprecated method
like thread.stop(), can I find the current running thread and stop it
?
4. Any suggested method to do the server stop which can stop the
current running java program in JVM ?
Thank you for helping
Calvin
- 7
- Toward more efficient ArrayListsRoedy Green (email***@***.com) wrote:
: IIRC Arraylists are about 10 times slower than plain arrays. This is
: quite a penalty to pay for not knowing ahead of time how many items
: you will have.
Can you give a pointer to a benchmark that shows this?
Or can you build a benchmark that shows this?
Can you give proof that this really is your hot spot? Most guesses
about what to optimize is wrong.
Anyway I find it hard to believe that arraylist is 10 times slower
since the methods (get and set) does something like
{ RangeCheck(index); return elementData[index]; }.
Ok the range check is unneccasry, it will be checked by the jvm also.
If you use add a lot then it will check the size of the array and
expand if neccessary. If you know in advance how many objects you will
store this should not be a problem (you do create the list with the
size), if you dont know in advance it will be hard to write something
that is a magnitude faster...
/robo
- 9
- Help sought trying to add java to mozilla 1.5
I've downloaded and gotten mozilla 1.5 to work on my desktop machine.
However, when I visit Java enabled sites, I get a popup that tells
me I am missing the plugin for the java-vm applet type. When I say
"download it", the only links are for windows and linux, and I'm
not using either of these.
In the java 1.4.2_01 directory I have on my machine is a rje/plugin/sparc/ns610
directory in which there is a .so file. But I don't see any instructions
on what all I need to connect things together.
When I try to copy that .so file into my $HOME/.mozilla/plugins directory,
mozilla 1.5 crashes attempting to access the java applets. If I
remove the .so, then I get a popup telling me I need a plugin.
Can anyone provide additional ideas on what might be missing?
--
<URL: http://wiki.tcl.tk/ > In God we trust.
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
<URL: mailto:email***@***.com > <URL: http://www.purl.org/NET/lvirden/ >
- 9
- want to sort tables inside a complex mechanism, what can be the approach?I have a situation where first we are fecthing some ids(list of say
version ids using hibernate form database)
then keeping those list of data in a Pager Object(Paging mechanism
displays 100 rows per page out of complete sa 100 or so.)
This pager class does two things one takes whole list of ids
(Collection of version_id).
(Every time based on search criteria it changes. For searching in
hibernate values are hardcoded. Want modification with minimal changes
as many things are interrelated here.)
and other thing it checks no. of contents based on that displays data
per page(100 here).
It means stores all data from database and send it oage by page.(First
thing to notice)
Next all this is getting stored in Report page where it searches other
column names based on ids(version_id) the other column names are
getting changed for different requests so what we do is take all other
columns collectAllExtraFields(this is also getting changed everytime
based on what is getting searched.)
Now all this is getting accumulated while displaying but as we know
what to display we hardcoded all fields required to display based on
search. But all fields are searched based on the id fetched from
database first time which Pages is storing.
like this
Search for product user information & retrun results in the form of a
paged table for components used by specific product
ComponentVersion versionObj =
versionHandler.getComponentVersion(versionId);
String CAUsers = ctHelp.getCAUsersSection(versionId);
tableBody = tableBody + ((i%2 == 0) ? "<tr
class='table_banded_row' valign='top'>" : "<tr class='table_row'
valign='top'>");
tableBody = tableBody + "<td class='table_data'>" +
procHelper.getCompVersionLink(versionId,
versionObj.getCompName(), versionObj.getCompVersion()) + "</td>";
tableBody = tableBody + "<td class='table_data'>" +
CAUsers + "</td>";
tableBody = tableBody + "<td class='table_data'><span
class='data'>" +
versionObj.getComponent().getType() + "</span></td>";
tableBody = tableBody + "<td class='table_data'><span
class='data'>" +
versionObj.getComponent().getVendor() + "</span></td>";
tableBody = tableBody + "<td class='table_data'><span
class='data'>" +
versionObj.getRecommendationType() + "</span></td>";
tableBody = tableBody + "</tr>";
/** Get ComponentVersion ID with hyperlink to ComponentVersion Detail
page
*/
public String getCompVersionLink(long versionId, String compName,
String compVersion){
return "<a class='datalink' title='" +
this.getComponentFlyOverText(versionId) + "'
href='/techstacks-v2_1/content/components/componentDetail.jsp?versionId="
+ versionId + "'>" + compName + " " + compVersion + "</a>";
}
this is getting called by Report.jsp to display.
As this is getting changed everytime its called form classes not used
in jsp directly i think.
Now original objective is to sort all these displayed columns.
If user clicks on any of the column name everything sholud get sorted
on that basis.but sholud not call databse for same again by using same
id and mapping with any new column name this sholud be done. Paging
mechinasm to be used as it is if possible without major changes.
i don't know where to start with as started looking on this code just
2-3 days back only.
Vj
- 10
- Problem with IN parameters to an Oracle stored procedureHello all
I had earlier posted the same problem I am having on
comp.java.lang.programmer earlier and someone suggested this post
would probably fall better under this group. Here is the link to the
original post with the original post copy pasted below.
http://groups.google.co.in/group/comp.lang.java.programmer/browse_thread/thread/b0b845981c3e403a/#
Since then I have changed the IN parameter to my stored procedure to
read as
clID IN TABLEA.CLIENTID%TYPE
instead of clientID, based on a suggestion to the earlier post and
have still had no luck.
Any suggestions are welcome.
Thanks
Swetha
- 10
- Beans with JSFI'm pretty new to programming with JSF and beans, and have been
reading up the documentation in the book "Core JavaServer Faces"
by D.Geary and C. Horstmann as well as online, and managed to
get some simple programs to run, so at least I now understand
some of the basics.
However, I've got quite a lot of existing code in HTML and
JavaScript that works, although not fully cleaned up yet, and I want
to make as few changes as possible in order to modify it for using
beans with JSF. Specifically, some months ago I wrote some
client-side code which is backed up online at
http://csharp.com/simulator/simulator.html, which I'm in the process
of modifying for JSF. The links at the bottom take you to
.../option1.html and .../option2.html, with the original source code
at
respectively .../option1.txt and .../option2.txt. At the moment the
code is not linked to code on a server, so only the JavaScript works
with the forms.
The index page didn't need much work, with the main change being
to include the JSF tags at the top (I'm leaving work on the counter
until later). The option1 page is mostly one large form, and what I
have since done is to keep the form as it is, except that it only
operates with JavaScript, with the post, action, and JavaScript
function calls at the beginning removed, together with the "Submit"
and "Reset" buttons at the end. I put these two buttons together
with calls to the JavaScript in a JSF form immediately below the
end of original form, and after making a few changes to the
JavaScript, got the JavaScript to work correctly and validate the
form.
My question is how do I send to the server the contents of the
original form, including the hidden fields? Do I have to create a
hidden field in the JSF form for each value entered in the main form,
and create a bean for each of these values, or is there some way
of sending the whole contents of the form to a bean, which can then
parse the values. I want to avoid turning the original form into a
JSF form, as it would probably mean making many changes to the
JavaScript, which would require extra work and debugging.
Exactly the same will be done with the option2 page once option1
has been sorted out, and I would be most grateful for some advice.
Christopher Sharp
- 14
- Help with JavaPOS pleaseHi there,
I have made an application that uses a POS printer device to print out a
receipt,
but there are genereal problems printing out .....
sometimes it prints out sometimes it doesn't (??) this is not the most major
of the
problems. The most major problem has to do with setting the style and the
layout of the printing.
After I have opened my device, claimed it everything should be ready or ??
I have checked to see what the method getFontTypefaceList()); returns
and my guess was that these numbers return different numbers that are
representatives for character sets eg fonts!!!! So I take one of these
numbers to try it out, put a number inside the method setCharacterSet(850);
yes .. 850 for instamce ... then I restart my application to see if the
output
is different, but it is not. I wonder why.
and yes I have tried several other methods in the POSprinter class and
by means of the POSprinterConst class too.
Does anyone have any experience with this or am I left to keep
experimenting?
I also need to find out how to set Linebreaking, linedistancing etc etc bold
italic and so on.
Regards
Carl
- 14
- Making a soundcard objectI have this idea of making a modem, that requires the soundcard to act
as my A/D and D/A, and in the middle will be my attempts at DSP. I
came up with this object, and it seems to test OK, but I could use
some constructive criticism, as I am definately at the OO 101 stage.
Merry Christmas, and a Happy New Years soon!
/**
* SoundCard.java
*
* @version 1.0, 1 December 2007
* @author Steve Sampson, K5OKC
*
* Public Domain (p) December 2007
*/
package modem;
import javax.sound.sampled.*;
import java.io.*;
public class SoundCard {
private static AudioFormat format;
private static TargetDataLine targetLine;
private static SourceDataLine sourceLine;
private static AudioInputStream sound;
public void SoundCard() {
}
/*
* Initialize Sound Card
*/
public boolean initPCM(double dblSampleRate) {
/*
* Encoding,
* Sample Rate (float),
* Sample Size (In Bits),
* Channels,
* Frame Size,
* Frame Rate (float),
* BigEndian (Boolean)
*/
format = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
(float)dblSampleRate,
16,
1,
2,
(float)dblSampleRate,
false);
DataLine.Info targetInfo = new
DataLine.Info(TargetDataLine.class, format);
DataLine.Info sourceInfo = new
DataLine.Info(SourceDataLine.class, format);
try {
/*
* A source data line is written to
*/
sourceLine =
(SourceDataLine)AudioSystem.getLine(sourceInfo);
sourceLine.open(format); // Typical buffer size is same
as samplerate in bytes
sourceLine.start();
/*
* A target data line is read from
*/
targetLine =
(TargetDataLine)AudioSystem.getLine(targetInfo);
targetLine.open(format); // Typical buffer size is same
as samplerate in bytes
targetLine.start();
}
catch (LineUnavailableException e1) {
return false;
}
catch (SecurityException e2) {
return false;
}
catch (IllegalArgumentException e3) {
return false;
}
catch (IllegalStateException e4) {
return false;
}
if(!AudioSystem.isLineSupported(targetInfo)) {
return false;
}
sound = new AudioInputStream(targetLine);
return true;
}
/*
* Stop, flush, and close the soundcard interface
*/
public void closePCM() {
sourceLine.stop();
targetLine.stop();
sourceLine.flush();
targetLine.flush();
try {
sourceLine.close();
targetLine.close();
}
catch (SecurityException e)
{
}
}
/*
* Provide a block of Signed 16 bit PCM sound data
*/
public int getPCM(int[] intSampleArray) {
int intBytesRead;
byte[] byteData = new byte[intSampleArray.length * 2]; //
Convert count to bytes
/*
* Read bytes into array. This call will block if there aren't
* enough requested bytes.
*/
try {
intBytesRead = sound.read(byteData, 0, byteData.length);
} catch(IOException e) {
return -1;
}
/*
* This is designed for Little-Endian Intel machines
*/
for (int i = 0, j = 0; i < intBytesRead; i += 2, j++)
intSampleArray[j] = (byteData[i + 1] << 8) + byteData[i];
return intBytesRead / 2; // convert count to words
}
}
|
| Author |
Message |
not

|
Posted: 2004-7-6 8:47:00 |
Top |
java-programmer, List help
Hi,
I am new to Java.
I've been working on this project for some time now and I cannot get it
to work.
This is supposed to be a linked list.
I need to use an insert method that alphabetically adds a new title to
the list. This code I have here doesn't have a working compareTo method
but only a test to add node to the list.
This code was provided to me and I must add an insert that will put a new
item in alphabetically order. Don't tell me the answer - I just don't
understand why this doesn't work. I hope that what I've written here is
clear.
Thanks
John
Main looks like this something like this:
main(String [] args){
BookList book = new BookList();
book.add (new Book ("title of book"));
}
// ----------------Test compareTo
public int compareTo(Node a, Node b){
// Since I couldn't get this to work either, I test to see if I can get
any value.
println(a.book.compareTo(b.book)); // doesn't work I don't know how to
compare the titles
return 0;
}
public class BookList
{
private BookNode head;
//----------------------------------------------------------------
// Sets up an initially empty list of books.
//----------------------------------------------------------------
BookList()
{
head = null;
}
//----------------------------------------------------------------
// Creates a new Book object and adds it to the end of
// the linked list.
//----------------------------------------------------------------
public void insert (Book newBook){
BookNode node = new BookNode (newBook);
BookNode current;
BookNode prev;
if (head == null)
head = node;
else
{
current = head;
while (current.next != null){
// Orignally this method looped through the whole list until it found the
end, then add the new
// to the bottom.
// I did a test here to see if I could move the list around.
// This is what I think should happen: save current in prev. get next with
current.
// try to put node in from of current.next. It seems no matter what I try
there's a null pointer
// error. I just can't figure this out.
prev = current;
current = current.next;
node.prev = current.prev;
node.next = current;
node.prev.next = node;
current.prev = node;
}
current.next = node;
}
}
//*****************************************************************
// An inner class that represents a node in the book list. The
// public variables are accessed by the BookList class.
//*****************************************************************
private class BookNode
{
public Book book;
public BookNode next;
public BookNode prev;
//--------------------------------------------------------------
// Sets up the node
//--------------------------------------------------------------
public BookNode (Book theBook)
{
book = theBook;
next = null;
prev = null;
}
}
}
|
| |
|
| |
 |
Roedy Green

|
Posted: 2004-7-6 9:54:00 |
Top |
java-programmer >> List help
On Mon, 05 Jul 2004 19:47:10 -0500, email***@***.com wrote or quoted :
>public int compareTo(Node a, Node b){
> // Since I couldn't get this to work either, I test to see if I can get
>any value.
>
> println(a.book.compareTo(b.book)); // doesn't work I don't know how to
>compare the titles
> return 0;
>}
See http://mindprod.com/jgloss/comparable.html
and http://mindprod.com/jgloss/comparator.html
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
| |
|
| |
 |
not

|
Posted: 2004-7-6 10:16:00 |
Top |
java-programmer >> List help
Thanks for that. I'll give it a try.
On Tue, 06 Jul 2004 01:53:56 GMT, Roedy Green
<email***@***.com> wrote:
> See http://mindprod.com/jgloss/comparable.html
> and http://mindprod.com/jgloss/comparator.html
Any idea what I'm doing wrong here? I think I am setting prev to current
then current to current.next. then putting the node between the two. Where
is the null pointer coming from?
That's the error I get. I shoule mention that in the main there are three
titles which are the other nodes.
public void insert (Book newBook){
BookNode node = new BookNode (newBook);
BookNode current;
BookNode prev;
if (head == null)
head = node;
else
{
current = head;
while (current.next != null){
prev = current;
current = current.next;
node.prev = current.prev;
node.next = current;
node.prev.next = node;
current.prev = node;
}
current.next = node;
}
}
|
| |
|
| |
 |
Roedy Green

|
Posted: 2004-7-6 11:09:00 |
Top |
java-programmer >> List help
On Mon, 05 Jul 2004 21:16:06 -0500, email***@***.com wrote or quoted :
>Any idea what I'm doing wrong here? I think I am setting prev to current
>then current to current.next. then putting the node between the two. Where
>is the null pointer coming from?
you can use a debugger trace the code and watch what happens step by
step. You can also print out references, which gives you a bit of a
clue.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
| |
|
| |
 |
Daniel Sj鯾lom

|
Posted: 2004-7-6 13:30:00 |
Top |
java-programmer >> List help
email***@***.com wrote:
> Thanks for that. I'll give it a try.
>
>
> On Tue, 06 Jul 2004 01:53:56 GMT, Roedy Green
> <email***@***.com> wrote:
>
>> See http://mindprod.com/jgloss/comparable.html
>> and http://mindprod.com/jgloss/comparator.html
>
>
>
> Any idea what I'm doing wrong here? I think I am setting prev to
> current then current to current.next. then putting the node between the
> two. Where is the null pointer coming from?
> That's the error I get. I shoule mention that in the main there are
> three titles which are the other nodes.
>
> public void insert (Book newBook){
>
> BookNode node = new BookNode (newBook);
> BookNode current;
> BookNode prev;
>
> if (head == null)
> head = node;
> else
> {
> current = head;
> while (current.next != null){
> prev = current;
> current = current.next;
>
> node.prev = current.prev;
> node.next = current;
> node.prev.next = node;
> current.prev = node;
>
> }
> current.next = node;
> }
> }
Consider what happens if there is only one node in the list (the head)
and you add another node. What does node.prev point to in that case? And
what happens when you add a third node after that?
It is also not clear what exactly you are trying to achieve with the
loop. It reminds me of a quote : "This is not right. It is not even
wrong" :-)
--
Daniel Sj鯾lom
Remove _NOSPAM to reply by mail
|
| |
|
| |
 |
john

|
Posted: 2004-7-7 9:34:00 |
Top |
java-programmer >> List help
On Tue, 06 Jul 2004 08:29:38 +0300, Daniel Sj鯾lom
<email***@***.com> wrote:
>> Any idea what I'm doing wrong here? I think I am setting prev to
>> current then current to current.next. then putting the node between
>> the two. Where is the null pointer coming from?
>> That's the error I get. I shoule mention that in the main there are
>> three titles which are the other nodes.
>> public void insert (Book newBook){
>> BookNode node = new BookNode (newBook);
>> BookNode current;
>> BookNode prev;
>> if (head == null)
>> head = node;
>> else
>> {
>> current = head;
>> while (current.next != null){
>> prev = current;
>> current = current.next;
>> node.prev = current.prev;
>> node.next = current;
>> node.prev.next = node;
>> current.prev = node;
>> }
>> current.next = node;
>> }
>> }
>
> Consider what happens if there is only one node in the list (the head)
> and you add another node. What does node.prev point to in that case?
Yes, I see. I had to modify the code that was given to me. Linked lists
are new to me. Christ, I didn't know what one was until the other day. I
think I could argue pretty well that my understand is not much better than
when I didn't know they existed. :P
I really didn't know what question to ask since I was having a hard time
with it.
Is a node simply a pointer to a reference variable? Can I get compare
data with a node? Or is a node ONLY a pointer to next the node? So if I
compared nodes, I'd comparing what the nodes pointed to, right?
> It is also not clear what exactly you are trying to achieve with the
> loop. It reminds me of a quote : "This is not right. It is not even
> wrong" :-)
Hey, wait. I've used that one. Jeez, I'm way off. Remember, I am new
*sniff*
Ignore the loop for a minute. When creating the 'current' reference in
the above code, what exactly happens there?
|
| |
|
| |
 |
Daniel Sj鯾lom

|
Posted: 2004-7-7 15:44:00 |
Top |
java-programmer >> List help
john wrote:
> On Tue, 06 Jul 2004 08:29:38 +0300, Daniel Sj鯾lom
> <email***@***.com> wrote:
>
>
>>> Any idea what I'm doing wrong here? I think I am setting prev to
>>> current then current to current.next. then putting the node between
>>> the two. Where is the null pointer coming from?
>>> That's the error I get. I shoule mention that in the main there are
>>> three titles which are the other nodes.
>
>
>>> public void insert (Book newBook){
>>> BookNode node = new BookNode (newBook);
>>> BookNode current;
>>> BookNode prev;
>>> if (head == null)
>>> head = node;
>>> else
>>> {
>>> current = head;
>>> while (current.next != null){
>>> prev = current;
>>> current = current.next;
>>> node.prev = current.prev;
>>> node.next = current;
>>> node.prev.next = node;
>>> current.prev = node;
>>> }
>>> current.next = node;
>>> }
>>> }
>>
>>
>> Consider what happens if there is only one node in the list (the head)
>> and you add another node. What does node.prev point to in that case?
>
>
> Yes, I see. I had to modify the code that was given to me. Linked
> lists are new to me. Christ, I didn't know what one was until the other
> day. I think I could argue pretty well that my understand is not much
> better than when I didn't know they existed. :P
I would suggest you start out with a singly linked list. It is slightly
easier to manage. Also, as a general programming tip, if you do not
understand something, you will not be able to program it. It is better
to work something out on paper first if the problem is too hard.
> I really didn't know what question to ask since I was having a hard
> time with it.
>
> Is a node simply a pointer to a reference variable?
A Node is a datatype, or simply a class. It contains two references
(next and prev) to other nodes. When you are using an object variable
(an instance of a class) you are always using a reference, in effect,
you are always manipulating what a variable refers or points to.
A reference is somewhat similar to a pointer in some other languages,
hence the NullPointerException. Unfortunately, java does not have
pointers! This is a confusing inconsistency in the naming of the
exception. It should be probably be named NullReferenceException instead.
Can I get
> compare data with a node?
Yes. You can compare the data (the book) in this case.
>Or is a node ONLY a pointer to next the node?
Well, a node is simply a node. A variable of type Node is a reference to
a Node object. But a Node object also *contains* references to two other
Node objects, prev and next.
> So if I compared nodes, I'd comparing what the nodes pointed to, right?
Yes. That is, if you write thisNode != thatNode, or thisNode ==
thatNode, you would be comparing the adresses that thisNode and thatNode
are stored at, not the contents of the nodes. To compare the books
contained in the nodes you need to write a Comparator.
>> It is also not clear what exactly you are trying to achieve with the
>> loop. It reminds me of a quote : "This is not right. It is not even
>> wrong" :-)
>
>
> Hey, wait. I've used that one. Jeez, I'm way off. Remember, I am
> new *sniff*
No offense intended. I know how frustrating it can be to debug something
for hours.
> Ignore the loop for a minute. When creating the 'current' reference
> in the above code, what exactly happens there?
>
When you say:
BookNode current;
you are simply creating a variable of type BookNode. It does not refer
or point to anything yet. In fact, if you try to use it directly after
declaring it, the compiler will complain about an unitialized variable.
Later, when you say:
current = head;
You are setting current to refer or point to the same object as the head
variable. If we ignore the loop and look at the statement after it:
current.next = node;
Here, we are setting the current.next field to point to node. If the
loop wasn't there, this would also mean that it sets head.next to point
to node, since head and current point to the same object. But we forgot
to set node.prev to point to current! It is still pointing at null. In a
doubly-linked list, we must always make sure that if someNode.next
points to anotherNode, then anotherNode.prev must point to someNode.
Whew! That was complicated. Or rather not complicated, but longwinded.
The gist of it is, that you cannot use objects directly in java. Instead
you are always accessing an object through a reference. Because spelling
all of this out takes a lot of effort, many java programmers just say
that they are using objects, or passing objects or whatever. This
further confuses newbies. Another confusing thing is that the rules work
differently for primitive types (int, long, float etc.), as opposed to
reference types.
If you are still confused, I suggest you try reading chapter 4 of the
java lanaguage specification (you can get it for free from
java.sun.com). It may be some heavy reading, but it is the
specification. If someone tries to argue that java doesn't work the way
described in there, they are wrong and you should ignore them.
--
Daniel Sj鯾lom
Remove _NOSPAM to reply by mail
|
| |
|
| |
 |
info

|
Posted: 2004-7-8 0:30:00 |
Top |
java-programmer >> List help
Ok, thanks for the help. One other thing:
Daniel Sj鯾lom <email***@***.com> wrote in message news:
> It is better
> to work something out on paper first if the problem is too hard.
I did do that, actually. Then it became apparent that I just didn't
understand what was happening. But by that time, I had spent so much
time on total failure that I got exhausted.
> A Node is a datatype, or simply a class. It contains two references
> (next and prev) to other nodes. When you are using an object variable
> (an instance of a class) you are always using a reference, in effect,
> you are always manipulating what a variable refers or points to.
>
OK. Makes sense.
> Can I get
> > compare data with a node?
>
> Yes. You can compare the data (the book) in this case.
OK, I add this in the book class:
public int compareTo(Book a){
return title.compareTo(a.title); // got help on this too
}
if main has:
BookList books = new BookList();
books.add (new Book("b"));
books.add (new Book("e"));
How do you compare a book that has no reference variable?
I tried :
current.compareTo(current.next); I just can't seem to get to the
data.
I'm compeletly baffled by how to access the data. I can't quite
understand why I can't get this. My attempts don't compile.
Thanks again for you help.
|
| |
|
| |
 |
Daniel Sj鯾lom

|
Posted: 2004-7-8 2:01:00 |
Top |
java-programmer >> List help
J wrote:
>>Can I get
>>
>>>compare data with a node?
>>
>>Yes. You can compare the data (the book) in this case.
>
>
> OK, I add this in the book class:
>
> public int compareTo(Book a){
> return title.compareTo(a.title); // got help on this too
> }
>
>
> if main has:
> BookList books = new BookList();
> books.add (new Book("b"));
> books.add (new Book("e"));
>
> How do you compare a book that has no reference variable?
> I tried :
> current.compareTo(current.next); I just can't seem to get to the
> data.
Presumably you want to compare the books contained in the nodes. In that
case you would say current.book.compareTo(current.next.book). Is that
what you meant? But you could also add this method to the Node class:
public int compareTo(Node n)
{
return book.compareTo(n.book);
}
Then current.compareTo(current.next) would work just as well.
--
Daniel Sj鯾lom
Remove _NOSPAM to reply by mail
|
| |
|
| |
 |
john

|
Posted: 2004-7-8 11:07:00 |
Top |
java-programmer >> List help
> Presumably you want to compare the books contained in the nodes. In that
> case you would say current.book.compareTo(current.next.book). Is that
> what you meant? But you could also add this method to the Node class:
>
> public int compareTo(Node n)
> {
> return book.compareTo(n.book);
> }
>
Yes, I've done that. (I'll double check though) It won't compile. I don't
know if I'm doing something really stupid. I just can't figure this out.
Spending all this time on this one assignment has caused me not only to
lose focus but my other work has suffered also.
I've added the method to the Node, the booklist and it doesn't work. I've
emailed the instructor but I haven't heard from him. It's like the some
kind of esoteric knowledge I can't know.
I have to put it away for awhile. I'm at the verge of a breakdown, one
foot in it, even.
Thanks for your help. I'm going to try again in a day or two. I REALLY
appreciate getting
pointers. I have to serious consider wether I'm cut out for programming.
> Then current.compareTo(current.next) would work just as well.
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
|
| |
|
| |
 |
Roedy Green

|
Posted: 2004-7-8 11:26:00 |
Top |
java-programmer >> List help
On Wed, 07 Jul 2004 22:07:13 -0500, john <email***@***.com> wrote or
quoted :
>It won't compile.
look up the errormessages at
http://mindprod.com/jgloss/errormessages.html
for some hints on what they really mean.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
|
| |
|
| |
 |
john

|
Posted: 2004-7-8 12:17:00 |
Top |
java-programmer >> List help
Excellent. Thanks.
On Thu, 08 Jul 2004 03:26:18 GMT, Roedy Green
<email***@***.com> wrote:
>
> look up the errormessages at
> http://mindprod.com/jgloss/errormessages.html
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- load servlet mappings at runtime in tomcatCan anyone suggest a way to achieve dynamic servlet mappings in tomcat 5.5.
What I want to do is run a web app with any number of paths all pointing to
one servlet. These paths would be loaded from a database and extra paths
can be added at runtime by the user. So an example would be
www.domain.com/sample and www.domain.com/anothersample would both execute
the same servlet.
Another option I thought of was having a custom 404 servlet that would check
the request supplied and then redirect.
- 2
- Opportunities in U.K./Great Britain?I have a friend who recently moved to Madrid. He had a Dutch passport
so EU access was relatively easy for him. We both lived in D.C., but
I remain US citizen by birth.
My question is, he says it's becoming more popular for J2EE
development in Great
Britain and the UK. I'm wondering how good is the market? (in
relation to US) How good is it for US programmers? (any demand for US
borne skills) And if any of these are true, how hard it is securing
work permit? (etc) Finally is there any idea what standard of living
might be like?
Given all of this would there be sacrifices, or would it just be
better overall simply to stay in US?
- 3
- using jsp:setProperty on non-simple types.Hi,
I'm currently having a small problem with my application. I'm using
some simple classes that wraps simple types to help me provide multiple
representation. For example, a DateCBO calls wraps the Date type and
gives me the oportunity to have various 'getters' like
getDateShortFormat(), getHtml(), getDateLongFormat() and so on.
My beans are using this kind of wrappers as their properties.
I have already made a custom tag to retrieve information that i use
instead of the standard jsp:getProperty
Now, i'm trying to use the jsp:setProperty to initialise the bean
property, but i have 'Could not coerce String to non-primitive type
StringCBO without bean property editor (JSP 1.2: 2.13.2.1) at line 13'
error.
Is there an interface that i can use to allow direct usage of
'jsp:setProperty', or should i create a custom tag as well.
thanks.
- 4
- JDialog focusHi,
Is it possible to ensure that, upon setVisible(true), a JDialog pop-up
jumps on top of all other windows including other applications?
Many thanks in advance!
Aaron Fude
- 5
- Four Mobile Phone Makers to Create Linux Platform
Roy Schestowitz wrote:
> Mobile phone companies join forces on Linux
>
> ,----[ Quote ]
> | Four mobile handset makers are teaming up with two cellular operators
> | to develop a new Linux software platform for mobile devices.
> |
> |
> | Cell phone makers Motorola, NEC, Panasonic Mobile Communications and
> | Samsung Electronics, along with mobile operators NTT DoCoMo and Vodafone,
> | expect to announce on Thursday plans to form an independent foundation to
> | develop a common mobile Linux-based platform. They will use this platform
> | to develop new products, applications and features.
> |
> | Linux, an open-source operating system, is already available on a wide
> | range of mobile handsets. Motorola alone says it has shipped more than
> | 5 million Linux-based handsets, mostly on smart phones, such as the
> | Ming model shipped in China. In addition, Motorola just launched the new
> | Rokr E2 music phone in Asia, which also uses Linux. The Rokr E2 will
> | soon ship in Europe.
> `----
>
> http://news.com.com/2100-1039_3-6083883.html?part=rss&tag=6083883&subj=news
>
> If this is not proof of GNU/Linux taking over, I don't know what is... Nokia,
> Palm and others are no exception.
Symbian is by far the dominant mobile OS worldwide and don't see that
changing soon, although tons of linux phone shipments to china, which
has the largest mobile subscriber base in the world holds hope.
As always, Java ME is the application platform for all these devices.
*Posted from my u know what...
- 6
- 7
- tomcatI just installed Tomcat 5.5 and went to http://127.0.0.1:8080/. Then I
clicked on Servlet Examples to see what examples it comes with, but I
got a 404 File not found error. Anyone know what the deal is? Are the
servlet examples separate?
- 8
- ain't java grand ?I just got this error message from the java 4.2 compiler.
---
Consulting.java:152: cannot resolve symbol
symbol : variable $
location: class Consulting
perchance you meant '.'
---
Ain't it just the coolest message you've ever seen?
- 9
- mouseClicked vs. mousePressed on Apple vs. WindowsI'm writing a Swing component which must function similarly on Apple
and Windows; and am having trouble with which event to fire off of
(this is effectively a toggle button which would ideally just be
interested in mouseClicked). For a variety of other reasons, I don't
want to make my code act on the mousePressed event.
Originally, our QA person asserted that it was busted because she was
clicking (and moving the mouse > 10 pixels) and it wasn't getting
"toggled" (this was on Windows). I won the battle there by saying
"don't move it 10 pixels; that's a drag, not a click". (after
debugging and figuring out that if you moved the mouse more than
approximately that much, the mouseClicked never came in).
However, she now claims that on Apple (OSX) that the button fails to
toggle if you move the mouse even one pixel while pressing the button.
(i.e. if you are not perfectly still while clicking).
Obviously this would be a different story. I don't have immediate
access to an Apple machine, so was wondering if anybody else had seen
this behavior. When I worked on the AWT on OS/2 at IBM, it was fairly
clear that the mouse events were determined based on native operating
system events (i.e. when Windows says it is a click, we'll say it is a
click). Don't know if that's true now or not, since I haven't seen the
code since Java 1.1.8.
---
Mike Dahmus
m dah mus @ at @ io.com
- 10
- Regular expressions question!I'm trying to parse HTML tables, so I need to find following pieces of text!
<table .....anything between this ..... /table> and
<tr ........ /tr> and
of course
<td> 'part that I need' </td>
I do not know how to put that into regular expression!
Thanks!
- 11
- How to convert a C++ Object to a JNI jobject in order to use GetObjectClassI have an interface object of type ISubscribe and I am trying to cast
the ISubscribe object to a jobject so I can call GetObjectClass in
order to proceed with a callback using JNI.
ISubscribe * s
jclass cls = env->GetObjectClass(s);
Does anyone know how I can do this in C++? I tried using
reinterpret_cast<jobject>(s) but GetObjectClass does not like that. Any
ideas would be appreciated.
Thanks,
Vijayk
- 12
- Eclipse 3.3 - external tool arguments issue.
I run the WebSphere command line wsadmin java tool as external tool in
Eclipse. It works fine except where an External tool argument has an
"=" sign as in "-javaoption -Dcom.ibm.ws.management.standalone2=xxxx".
Wsadmin picks up the "-Dcom.ibm.ws.management.standalone2" variable
but not the value. Seems that the Eclipse "arguments" dialog
truncates values after the "=" sign. Is there a way around this.
The arguments are listed below.
-user 1234 -password xyz
-lang jacl -host 11.11.11.11. -port 1111
-javaoption -Dcom.ibm.ws.management.standalone2=xxxx
-wsadmin_classpath C:\WASAdminSBV\WSAdmin\WAS5.1\JACL\proclib.jar
-f ${resource_loc}
The problem does not occur when Wsadmin is run from the command line.
- 13
- jni gcc mangled names//Crapo.java
public class Crapo {
static {
System.loadLibrary("Crapo");
}
native public static int magicNumber(int n);
public static void main(String... args) {
System.out.println(magicNumber(246));
}
}
//Crapo.c
typedef long long __int64;//gcc doesn't recognize __int64
#include "Crapo.h"
/*
* Class: Crapo
* Method: magicNumber
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_Crapo_magicNumber(JNIEnv * env, jclass c,
jint n) {
return 47;
}
//run gcc -mno-cygwin -Wl,--add-stdcall-alias -shared -o Crapo.dll -I
"C:\Program Files\Java\jdk1.6.0\include" -I "C:\Program
Files\Java\jdk1.6.0\include\win32" Crapo.c
//output of nm Crapo.dll
10003040 b .bss
10003020 b .bss
10003000 b .bss
//............ 30+ lines of this crap
1000505c i .idata$5
//..........................
100011d0 T _DllMain@12
10001000 T _DllMainCRTStartup@12
100011c0 T _Java_Crapo_magicNumber@12//<-----------------
10001360 T __CTOR_LIST__
10001368 T __DTOR_LIST__
U __RUNTIME_PSEUDO_RELOC_LIST_END__
U __RUNTIME_PSEUDO_RELOC_LIST__
//................... more crap; to me at least
//it was my understanding that --add-stdcall-alias when passed to the
linker should remove the @12 of _Java_Crapo_magicNumber@12
//run gcc -mno-cygwin -shared -o Crapo.src -S -I "C:\Program
Files\Java\jdk1.6.0\include" -I "C:\Program
Files\Java\jdk1.6.0\include\win32" Crapo.c
//remove @12 from Crapo.src
//run as -o Crapo.obj Crapo.src
//run ld -shared -o Crapo.dll Crapo.obj
//run nm Crapo.dll
U .bss
U .data
10001000 t .text
10001000 T _Java_Crapo_magicNumber
10001010 T __CTOR_LIST__
10001018 T __DTOR_LIST__
10002000 A __RUNTIME_PSEUDO_RELOC_LIST_END__
10002000 A __RUNTIME_PSEUDO_RELOC_LIST__
10001010 T ___CTOR_LIST__
10001018 T ___DTOR_LIST__
//... more crap
// by manually removing the @12 from the assembly source produced by
gcc and then separately assembling and linking solves the problem.
//I like the fact that their are far fewer unnecessary symbolic names.
Yet I was hoping their was a one step command-line option to be sent,
like --add-stdcall-alias? Any reason that doesn't seem to work for me?
//It's my understanding that -Wl,--add-stdcall-alias command-line
option is sent to the linker by gcc, and then subsequently sent to
dlltool where the option should result in the @nn's being removed from
the table of symbolic names. Is this correct?
- 14
- ... to see if I can post ...
I attempted to respond to the response to my latest post,
or to thank him twice, but not shown. What is going on?
- 15
- Play audio clip in an ApplicationI'm trying to play an audio clip by using Applet's newAudioClip()
method. That method takes a URL. The .wav file is located in a jar file
(the only jar file). For example:
if myJar.jar is the only jar file
"java -jar myJar.jar" launches the application correctly and everything
is wonderful. My audio clip won't play because I don't know how to
access the .wav file from the jar file.
This code snippet works fine when I'm not running from the jar file:
try
{
File currentDir = new File(".");
URL currentDirURL = currentDir.toURL();
URL url = new URL(currentDirURL, fileName);
AudioClip clip = Applet.newAudioClip(url);
clip.play();
}
catch (Exception e)
{
e.printStackTrace();
}
It knows to look for the sound file in the current directory. How do I
adjust this code to look for the sound file in the jar.
I have a feeling it's an easy answer involving class.getResource().....
|
|
|