Dennis Hicks

Greenhorn
+ Follow
since Jul 09, 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 Dennis Hicks

Thanks for the tip - I didn't think of running a host machine tool to find it out. :roll:
I was just hoping to do it all in the code and not have to call an external tool, but I guess I can invoke netstat. How I'll parse the output from it, I have no idea.
Thanks again,
Den
Hi all -
I apologise if this has been covered already, but I did a quick search and couldn't find an answer.
I'm trying to find a way of finding out what ports/sockets are open on a machine at any point in time - so I'm after some method to return a list of open ports.
Ideally I was hoping there'd be a method in java.net that returned an enumeration of open ServerSockets that I could traverse, but couldn't find anything.
Has anyone done this or have any ideas? There's plenty of examples showing how to open a ServerSocket and then connect to that known socket - but what if you don't know the port number?
Cheers-
Den
I also like the "Mastering EJB & the Java 2 Platform, Enterprise Edition" book by Ed Roman, published by Wiley.
I believe that there's a EJB 2.0 version on the way soon - you can look at it on the serverside.com web site if you register and also download the book in .pdf format.
Den
Hi -

System.gc() cannot force the garbage collector to run it merely requests that the garbage collector runs.
I'm also under the impression that even though the gc runs and objects are eligible for garbage collection, there is no guarantee that the objects will be garbage collected - the gc thread could be interrupted by a higher priority thread and stop garbage collecting.
Den
Swing is in the programmers' exam - section 8 covers the java.awt package, and I guess as Sun prefers you to use Swing rather than AWT now, that Swing is the bulk of the tested material in this section?
Can someone who has sat and passed the exam pass any comments - please ;-)
Cheers -
Den
20 years ago

An instance of a class can have its state (all the values of its' member variables) written to permanent storage - a process known as serialization (can't get used to that z!).
So when it says 'persistent state' it simply means the state of the object that survives and can be recreated from the serialized representation of the class.
Member variables marked as transient are not included when the object is serialized - the values of these are lost. One assumes they will be given the appropriate default values when the class is recreated.
So, the answer to you question is to declare the variable as transient.
Cheers,
Den
20 years ago

Hi all -
I'm preparing for my SCJP exam and have checked the objectives out on the sun web site and in my book - I can't see applets as something that is tested - it seems to only be tested in the architects' exam - I just want to be sure - are they covered in the exam?
Also, just how much detail do you have to commit to memory about Swing? I was playing about with it today and looking at event handling - surely Sun can't expect you to commit all of that to memory?
Thanks -
Den
20 years ago
That's great, thanks for pointing it out and showing the flow of execution.
For some reason I thought that super() would be calling the Light class no-args constructor, but of course, it isn't! ;-)
Stupid brain....
Thanks again -
Den
20 years ago
And for reference - Java in a nutshell, Flanagan, O'Reilly publishers.
It's got a brilliant class index at the back....
20 years ago
I believe that you always get an int result (or a larger data type) as a result of an arithmetic operation.
If your operation involves data types narrower than an int, they are implictly converted to ints - that's what I believe anyway.
Say:
byte a = 2;
byte b = 3;
byte c = a * b; // will not work, as result is int type
but....
byte c = (byte) a * b; // will work...

But say you did:

double a = 2.0;
double b = 3.0;
double c = 0.0;
c = a * b;
System.out.println ("Result: " + c);
This would return a doube result ok.
20 years ago
Hi -
I'm using 'A programmers guide to Java certification - a comprehensive primer' by Khalid Mughal and Rolf Rasmussen.
It's certainly got loads of code examples and questions in it.
I think that it's a very good book - IMHO
Cheers,
Den
20 years ago

I'm studying for the SCJP - but CTOR chaining is confusing me. The following code is from A programmers guide to Java certification (great book):

class Light
{
// instance variables

private int noOfWatts;
private boolean indicator;
private String location;
// CTORS
Light()
{
this (0, false);
System.out.println ("Returning from default constructor no. 1 in class Light");
}
Light (int watt, boolean ind)
{
this (watt, ind, "X");
System.out.println ("Returning from non-default constructor no. 2 in class Light");
}
Light (int noOfWatts, boolean indicator, String location)
{
super();
this.noOfWatts = noOfWatts;
this.indicator = indicator;
this.location = new String (location);
System.out.println ("Returning from non-default constructor no. 3 in class Light");
}
}

class TubeLight extends Light
{
// instance variables
private int tubeLength;
private int colorNo;
// CTORS
TubeLight (int tubeLength, int colorNo)
{
this (tubeLength, colorNo, 100, true, "Unknown");
System.out.println ("Returning from non-default constructor no. 1 in class TubeLight");
}
TubeLight (int tubeLength, int colorNo, int noOfWatts, boolean indicator, String location)
{
super (noOfWatts, indicator, location);
this.tubeLength = tubeLength;
this.colorNo = colorNo;
System.out.println ("Returning from non-default constructor no. 2 in class TubeLight");
}
}
public class Chaining
{
public static void main (String[] args)
{
System.out.println ("Creating a new TubeLight object");
TubeLight tubeLightRef = new TubeLight (20, 5);
}
}
I can't understand why the output looks like this:

Creating a TubeLight object.
Returning from non-default constructor no. 3 in class Light
Returning from non-default constructor no. 2 in class TubeLight
Returning from non-default constructor no. 1 in class TubeLight
Why don't I see any of the prints from CTORs 1 and 2 in the Light class?

Cheers for any insights -
Den
20 years ago