|
|
|
1000 Java Tips ebook
|
|
 

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!. |
|
Java Newsletters Archive: 3
|
JavaFAQ Home » Java Newsletters

New Page 1
Hello dear subsribers!
We continue to send you our daily Java tips!
And here our tips! (will appear on our site just 27 Sept.)
***********************************************
Tip1
Q: I am experimenting with a Java server
application. This program
has worked well.
It did start on the Red Hat Linux 6.0 server, but it does not
open the socket, in other words, it cannot communicate with
the client applet on the Linux. On this Linux server I have
installed every components and all of them were running at
the experiment time. Why does this server application
communicate with the client applet only on the Linux?
A: Take a look at your port number. If it is
under 1024, it is
a protected port number and non-privileged users cannot
touch it on Linux or any other Unix-system.
........................................................................
Tip 2
Q: I'm having trouble figuring out how to
convert characters
to their ASCII value in java. Is there a class like
NumberFormat that will do it?
A: We can't see any problem here:
char ch = 'A'; // character 'A'
int i = (int)ch; // ASCII value for 'A' (=>65)
P.S.Yes! And just be aware that ASCII only runs from 0
through 127. Anything higher needs to be addressed
differently, since Java is using Unicode values.
........................................................................
Tip 3
Q: The following app works fine, but when I
start it, I cannot
close it using the X at the right top of the form...
Please help me on the following. I'm just starting to use
java (JDK1.3). The following app. works fine, but when
I start it, I cannot close it using the X at the right top
of the form. What should I add to fix this problem? The
source is shown below:
import java.awt.*;
import java.awt.event.*;
public class MyApplication extends Frame{
public static void main(String args[]){
Frame f = new Frame("MyApp");
f.setLayout(new FlowLayout());
f.add(new Button("A"));
f.setVisible(true);
}
}
A: In Java You should yourself add a
listener to handle
the closing of the window when the X box gets clicked on.
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt){
System.exit(0);
}
});
Read on this, and other ways to do it, in the sections dealing with
event handling, in whichever Java text you are using.
........................................................................
Tip 4
Q: How do I use object serializtion for an
object that has other
objects as data member? Do both the class need to implement
serialize? How about static data?
class A{
}
class B{
public A a;
}
A: Both the object and all the object
references it contains need
to belong to classes that implement Serializable.
Static and transient fields are not serialized. For more, see,
http://java.sun.com/docs/books/tutorial/essential/io/serialization.html
........................................................................
Tip 5
A: I recently learned a bit about "inner
classes" but this seems
to be different...
Q: I'm a bit new to Java programming so bear
with me. My
employer bought a package of java graphics library programs
to support some chart applets we want to create. We have
the source code. I'm trying to create a jar file with all the
files I need to run the applet. When I currently run the applet,
the browser java tool says that it can't find
"TextComponent$1.class". I recently learned a bit about
"inner classes" but this seems to be different. The "
TextComponent.java" file does contain some inner classes,
but not a class called "1". I'm confused. Is this an inner class?
Or is it something else. Any help would be appreciated.
Thanks...
A: The TextComponent$1.class is the first
anonymous class
defined in TextComponent.java. Since nested (inner) classes
are compiled to their own .class file, they needed unique
names. The javac compiler is just creating a unique file
name for an anonymous nested class.
........................................................................
Tip 6
Q: Is there any way to manage Systray Icons
with Java? I didn't
even find anything in the Microsoft packages...
A: You must create a C/C++ program that
calls directly the
NotifyIcon API to display/manage the Icon in the Systray.
Then call the program from Java with JNI.
........................................................................
Tip 7
Q: I want to be able to print debugging text
messages during the
whole applet's lifetime. Is there an easy way to do that???
I'm a beginner in java. Right now i am doing an applet and
I want to write messages to the browser window for
debugging purposes i.e. to follow how the applet executes.
Like when i'm developing a C++ application i usually use
lots of "couts" to check values and the programs behavior.
Is there an easy way to do things like that when making a
Java applet? For me it seems like everything happens in a
function called "paint(graphics g)" and that function is only
called at the beginning of the applet start. I want to be able
to print text messages during the whole applet's lifetime.
Is there an easy way to do that???
A: you'd be better off doing a
System.out.println("the value is " + whateverValue);
This will show up in the java console. to see it in IE5, do
View->Java Console, and in netscape4.7, do Communicator->Tools->Java
Console and it will pop up the java console window.
If you are doing it in appletviewer from dos, it will show up
in the dos window you used to call appletviewer.
Printer Friendly Page
Send to a Friend
..
Search here again if you need more info!
|
|
|