Originally Posted by
Norm
This compiles and executes:
PortSelector.getPortNumber().toString()
static methods don't require an object
port not being static can't be referenced from a static method.
Well, yes, I could have called getPortNumber() directly from main() ~ I was in a hurry. It did run, I did get a port number. The fact that I went through a call to new sort of blurs our discussion, yes but even with an object:
PortSelector portSelector = new PortSelector();
I can still call getPortNumber on portSelector. It is a matter of a few instructions to access a variable sized memory allocation called the heap. An early form of failure in programs called stack crash was when the heap would grow so big as to overrun the physical addresses where the running program stacks things up.
Because I was using Java, I could just code something to get a random port number and prototype not worrying about matters like that. If it failed, I just get an Exception and main() returns control to the JVM without breaking my machine.
Originally Posted by
Norm
Besides the fact that: while((port < 49152) || (port > 65535)); will loop forever it port is out of range?
This method of searching is extremely powerful when the size of the dataset vastly exceeds the search window available. We have a call to next random in there somewhere, if not you have a valid point. These rarely go past a few milliseconds to get something in range. You can try narrowing the window but I promise up front on the board that no book you can find will ever tell you how to sit on the keyboard without trapping a Thread in a while() loop. While loops consume processor power, power that is needed if we are to keep the machine responsive. A good exercise would be to put a ++int if int greater than loop limit, discard request and report failure to System.out
I coded something that sits on the keyboard to watch for keystrokes but consumes almost no processor power. Good exercise for you. Work on it, post in beginner and read Algorighms in Java by Sedgewick. Really effective tool for someone with your skill level.
In fact, one could focus the search window on some specific area of the dataset by using a next Gaussian method already available in the libraries. Tell ya what, Bocephus, center my search on the desired range using a next Gaussian. While you are sitting there in an all night hair puller be sure to Amazon a copy of Sedgwick's masterwork. Some of the techiques in Cave Oriented Bloated Oh Languge can be prototyped in Java very effectively using the cited work. Doing so will prevent moderators watching me suffer your unresearched stumbling.
( Pro's here folks, don't worry about it )
Am I looking at the same code as you are?
Probably, but I think you need to look a little closer.
Why post code with so many errors?
What error, where? Here, hava port number:
I think it is in hexadecimal ~ that was the first toString I found in the sources. Help me here, boss -> did I call toHexString(int i) or call toString(int i)
My beers were/will be British ales.
Those tend to be too stout and bitter for me. I need a moderately smooth Lager.