Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HELP JDK 1.1 NOT COMPILING - java-help.txt (1/1)

1 view
Skip to first unread message

tony

unread,
Mar 19, 1997, 3:00:00 AM3/19/97
to

begin 644 java-help.txt
<uuencoded_portion_removed>
J04Y4+D1%34].+D-/+E5+*2`-"B`@("`@("`@("`@("`@("`@("`@("`@
`
end

Kevin ENglish

unread,
Mar 19, 1997, 3:00:00 AM3/19/97
to

tony wrote:
>
> I WONDER IF SOMEBODY CAN HELP ME I AM NEW TO JAVA PROGRAMING,BUT i HAVE
> DOWNLOADED & INSTALLED THE JDK1.1 AND FOLLOWED THE INSTALLATION
> INSTRUCTIONS .IE I HAVE SET THE PATH TO
> PATH C:\WINDOWS;C:\WINDOWS\COMMAND;C:\;C:\DOS;C:\JDK1.1\BIN
> SET CLASSPATH=.;C:\JDK1.1\LIB\CLASSES.ZIP
> THE PROGRAM RUNS THE DEMOS OK WITH THE APPLETVIEWER
> BUT WHEN I TRY TO COMPILE A SIMPLE HELLOWORLD PROG LIKE THE
> FOLLOWING
> CLASS HELLOWORLD{
> PUBLIC STATIC VOID MAIN(STRING ARGS[]){
> SYSTEM.OUT.PRINTLN("HELLOWORLD");
> }
> }
> i GET THE FOLLOWING ERROR MESSAGES
> class string NOT FOUND IN TYPE DECLARATION:
> PUBLIC STATIC VOID MAIN(STRING ARGS[])
> &
> UNDEFINED VARIABLE ,CLASS ,OR PACKAGE NAME:SYSTEM
> SYSTEM.OUT.PRINTLN("HELLO WORLD")
>
> THERE ARE ARROWS THAT POINT TO MAIN & SYSTEM IN THE TWO ERROR
> STATEMENTS ABOVE
> I WOULD BE VERY GRATEFUL FOR ANY HELP
>
> REGARDS
> TONY(TO...@ATOMANT.DEMON.CO.UK)
>
I too am new, I get the a weird error that says the class is not found.
Also I can't compile using the javamaker that came with my beta 2.0 Cd.
I use win 95. In the dos and 95 mode, the file extenstions are cut so I
thought maybe it's that but I don't know.
If someone know, let me know

Glen Walters

unread,
Mar 20, 1997, 3:00:00 AM3/20/97
to

tony wrote:
>
> I WONDER IF SOMEBODY CAN HELP ME I AM NEW TO JAVA PROGRAMING,BUT i HAVE
> DOWNLOADED & INSTALLED THE JDK1.1 AND FOLLOWED THE INSTALLATION
> INSTRUCTIONS .IE I HAVE SET THE PATH TO
> PATH C:\WINDOWS;C:\WINDOWS\COMMAND;C:\;C:\DOS;C:\JDK1.1\BIN
> SET CLASSPATH=.;C:\JDK1.1\LIB\CLASSES.ZIP
> THE PROGRAM RUNS THE DEMOS OK WITH THE APPLETVIEWER
> BUT WHEN I TRY TO COMPILE A SIMPLE HELLOWORLD PROG LIKE THE
> FOLLOWING
> CLASS HELLOWORLD{
> PUBLIC STATIC VOID MAIN(STRING ARGS[]){
> SYSTEM.OUT.PRINTLN("HELLOWORLD");
> }
> }
> i GET THE FOLLOWING ERROR MESSAGES
> class string NOT FOUND IN TYPE DECLARATION:
> PUBLIC STATIC VOID MAIN(STRING ARGS[])
> &
> UNDEFINED VARIABLE ,CLASS ,OR PACKAGE NAME:SYSTEM
> SYSTEM.OUT.PRINTLN("HELLO WORLD")
>
> THERE ARE ARROWS THAT POINT TO MAIN & SYSTEM IN THE TWO ERROR
> STATEMENTS ABOVE
> I WOULD BE VERY GRATEFUL FOR ANY HELP
>
> REGARDS
> TONY(TO...@ATOMANT.DEMON.CO.UK)
>

Java is case-sensitive. This aint FORTRAN. :-)

Peter van der Linden

unread,
Mar 20, 1997, 3:00:00 AM3/20/97
to

>> CLASS HELLOWORLD{
>> PUBLIC STATIC VOID MAIN(STRING ARGS[]){
>> SYSTEM.OUT.PRINTLN("HELLOWORLD");

Java is case sensitive. "STRING" is not the same as "String".
Try your program again without everything in capitals (that's a good
idea for postings too).


>I too am new, I get the a weird error that says the class is not found.
>Also I can't compile using the javamaker that came with my beta 2.0 Cd.

Check the list of frequent problems in the FAQ....


version: comp.lang.java.programmer FAQ list Mar 17 1997, Peter van der Linden.

Most of the entries on this Java FAQ list are intended for experienced
programmers. To distinguish it from other Java FAQs, this is termed
the "Programmer's FAQ" and will be posted mostly in comp.lang.java.programmer.

FAQ is available at: http://www.best.com/~pvdl

-------------------------------------------------------------------------
0. LOOKING FOR INFORMATION

0.1 How do I search Deja News for past postings on Java topics, e.g. the FAQ?

A. Go to http://www.dejanews.com/forms/dnsetfilter.html

Under "Newsgroups" enter "comp.lang.java.programmer" (or whatever)
Under "Subject" enter "Frotteur" (or other topic you find pressing)
Click "Create Filter"
It will go to a new document, and you should click the link labelled
"nnn Documents" ("nnn" is some number).

Warning: this makes finding information so easy, you can spend a lot of
time doing it...


0.2 How do I check on known bugs in JDK 1.1?

A. look at http://java.sun.com/products/jdk/1.1/knownbugs/index.html


0.3 How do I translate C/C++ into Java or vice-versa?

A. In general it is not simple to translate C/C++ into Java, as
Java lacks the arbitrary pointer arithmetic of those languages. If
your C code does not use pointer arithmetic, automatic translation
gets a lot simpler. [anyone who has URLs of translation tools,
please send them]

There are currently three freely-available tools to translate Java
into C:
- j2c from Japan,
- Toba from the Sumatra research project, and
- JCC from Nik Shaylor.
None of them support the AWT yet, and both j2c and JCC have
additional restrictions. [Again, URL details are sought.]


-------------------------------------------------------------------------
1. LANGUAGE ISSUES
1.1 Why doesn't my "hello world" program work?

A. Two very common causes of failure are:
* the class name and the file name must match exactly, even letter case.
If your class is HelloWorld, your source file must be HelloWorld.java
* the $CLASSPATH environment variable should include "." (current dir).

1.2 How can I program linked lists if Java doesn't have pointers?

A. Of all the misconceptions about Java, this is the most egregious. Java
has pointers (it calls them "references"). It does not have pointer
arithmetic or untyped casting. By removing the ability for programmers to
create and modify pointers in arbitrary ways, Java makes memory management
more reliable, while still allowing dynamic data structures.

A linked list class in Java might start like this:
public class linkedlist {
public linkedlist next;
public static linkedlist head;
public linkedlist next(linkedlist current) { ...
... }

Another choice for a linked list structure is to use the built-in class
java.util.Vector which accepts and stores arbitrary amounts of Object data
(as a linked list does), and retrieves it by index number on demand (as an
array does). It grows automatically as needed to accommodate more elements.
Insertion at the front of a Vector is a slow operation compared with
insertion in a linked list, but retrieval is fast. Which is more important
in the application you have?


1.3 What is the true story about how parameters are passed in Java? Is is
by value or by reference?

A. All parameters (values of primitive types, and values that are references to
objects) are passed by value [JLS sect 8.4.1]. However this does not tell
the whole story, as objects are always manipulated through reference
variables in Java. Thus one can equally say that Objects are passed by
reference (and the reference variable is passed by value). This is a
consequence of the fact that variables do not take on the values of
"objects" but values of "references to objects".

Bottom line: primitive type arguments (int, char, etc) _do not_ change
when the corresponding parameter is changed. The fields of object type
arguments _do_ change when the corresponding parameter fields are changed.

1.4 Why the *&%$# is String final?

A. There are several reasons.
The simplest is that being final guarantees that instances of String are
immutable. (The String class implements immutable objects, but if it
were not final it would be possible to write a subclass of String which
permitted instances to be changed.) But that's an unsatisfying answer,
because the real question is "Why must Strings be immutable?"

One reason is efficiency. It's easier to optimize accesses to an object
that is known to be immutable. Strings are very commonly used, even
used behind the scenes by the Java compiler. Efficiency gains in the
String class can yield big dividends.

A more compelling reason is security. Before String was changed to be
final (while Java 1.0 was still in beta) there was a race condition which
could be used to subvert security restrictions. It had to do with having
one thread change a pathname while another thread was about to open it.

There are other ways to solve these problems, but making String final
is the one that the designers chose.

1.5 How are finalizers different from C++ destructors?

A. Java objects are not explicitly deleted and do not have destructors.
Instead they are implicitly garbage collected when the JVM realises your
program can no longer access them. Typically this technology is _not_
based on reference counting and _will_ cope with circular references.

Every object has a routine called finalize() which will be called before
the object is collected. This is Java's nearest equivalent to C++'s
destructor. However, it is not a good idea to rely on finalisation for the
timely freeing of resources.

This is because garbage collection and hence finalization may be
arbitrarily delayed, and may never happen at all if the program terminates
before it runs out of memory. You should instead provide your objects with
methods similar to Graphics.dispose() to free resources, and call the
dispose() method explicitly when you have finished using them - typically
within the "finally" clause of a "try/catch" block. You may then call your
dispose() method from within your finalize() method as a last-ditch
attempt to free the resource if someone forgets.

Alas, all this means the C++ idiom of "object construction is resource
aquisition" does not translate well to Java. However, note that 90% of
destructors in C++ are there to free memory, and the GC means you don't
need to do that in Java. As well as fixing an important source of bugs,
the GC is essential to Java's security model; without it you could forge
object references by preserving the reference after the object has been
deleted.

If your program appears to be crashing due to running out of some system
resource (like File, Window or Graphics handles), it probably because the
system is running out handles before it has run out of memory. Check that
you have called the dispose() method (or equivalent) on every object that
uses system resources. You can help the GC a little bit more by explicitly
NULLing out references that you've finished with.

1.6 What happened to "private protected"?

A. It first appeared in JDK 1.0 FCS (it had not been in the Beta's). Then it
was removed in JDK 1.0.1. It was complicated to explain, it was an
ugly hack syntax-wise, and it didn't fit consistently with the other
access modifiers. More people disliked it than liked it, and it added
very little capability to the language. It's always a bad idea to reuse
existing keywords with a different meaning. Using two of them together
only compounds the sin.

1.7 What's the Java equivalent of sizeof()?

A: There isn't one. sizeof() in C and C++ is used in three main places:

1) To check on the size of a primitive type. In Java, the
sizes of primitive types are fixed in the language specification
(a short is _always_ 16 bits; an int is _always_ 32 bits, etc),
so this is no longer necessary.

2) In memory allocation (i.e. malloc (32 * (sizeof(int));)
In Java you always allocate a specific type of object, rather
than a block of raw memory that you will fill as you like.
The system always knows the size of the kind of objects you are
allocating. So sizeof is not needed.

3) in pointer arithmetic (i.e. p += sizeof (int)) Pointer
arithmetic of this type is not allowed in Java, so this
isn't necessary, either.

For all these reasons, there is no need for a Java sizeof() operator.

1.8 I extended the class called Frotz, and the compiler is giving me
an error message "No constuctor Frotz() in the class". Why?

A. When you define a constructor for a class, unless you explicitly
call the superclass's constructor at the start, a call to the
superclass's parameterless constructor is implicitly inserted.
The problem you're seeing is what happens when the superclass
doesn't *have* a parameterless constructor. The solution is
usually to call the correct version of the superclass's constructor
with the right parameters.


-------------------------------------------------------------------------
2. APPLETS and AWT

2.1 My applet works on my machine, but fails when I put it on our web server.
Why?

A. It could be one of several reasons, and unfortunately the messages
that you get in this situation aren't much help. In general, you can
assume that either your applet's class files are corrupted somehow, or
the web server can't find one or more of them when the browser needs
them.

Be careful of the following things:
- Make sure you transfer the class files in binary mode, rather than
text or ASCII mode.
- Make sure you transfer *all* of the class files which are a part
of your applet. Sometimes people are surprised by how many there
are. There will be a class file for every class and interface you
define, even if you define more than one in a single source file.
If you use the Java 1.1 "inner classes" feature, there will be class
files for each inner class as well.
- Make sure you maintain the appropriate case distinctions in your
filenames. If a class is called StUdLy, it must be found in a
file called StUdLy.class.
- Make sure you maintain the directory structure that matches your
package structure. If you declare a class in package
COM.foo.util, the class file needs to be in directory COM/foo/util
under the applet's codebase directory. Again, case distinctions
are important for package/directory names, just as they are for
class/file names.
- Make sure that the web server process will have read access to the
class files, and search access to the directories that the files
are in. For example, if the web server runs on a Unix machine, use
the command "chmod o+r filename" for the files, and
"chmod o+x dirname" for the directories.

2.2 Why do I get this when using JDK 1.1 under X Windows?
java.lang.NullPointerException
at sun.awt.motif.MFramePeer.<init>(MFramePeer.java:59)
at sun.awt.motif.MToolkit.createFrame(MToolkit.java:153)
at java.awt.Frame.addNotify(Frame.java)
at java.awt.Window.pack(Window.java)

A. There's a missing font on your system. Move font.properties from
the "lib" subdirectory aside to font.properties.bak Then it won't
look for the font and fail to find it.

The problem occurs because the Motif AWT libraries use
the Font "plain Dialog 12 point" as a fall-back default font.
Unfortunately, when using a remote X server sometimes this font isn't
available.


2.3 how do you make the applet's background transparent?

A. there is no way to give an applet a transparent background that
lets the web browser background show through. You can simulate it
by giving the applet a background that matches the underlying browser
background. It doesn't produce satisfactory results with a patterned
background because of problems aligning the edges.

2.4 How do you do file I/O from an applet?

A. The following suggestions are for server-side I/O.
1. Read a file by opening a connection using the URL
class and then using a DataInputStream to read the data.
This allows reading but not writing. It requires an http demon
running on the server, which will usually be the case.
2. Or open a socket back to the server and read/write the data. Have a
process on the server that listens for socket connections from
applets and does the requisite I/O. This does I/O on the server.
3. Or use a CGI script or servlet on the server to write when browsed.
There is some source at ftp://ftp.oyster.co.uk/pub/java/fileIO/

The following suggestions are for client-side I/O.
4. Use a trusted applet (see section on security). This will
eventually permit local I/O.
5. Or use a browser that has a security policy that is configured to
allow file I/O (such as Sun's appletviewer).

2.5 Why is GridBagLayout so hard to use?

A. GridBagLayout was contributed to Javasoft by a programmer who wanted to
support the Java effort. It was intended as a proof that the AWT offered
enough features for programmers to write their own layout managers. It
wasn't designed with human factors and ease of use in mind.
If it bothers you (it bothers me) then just don't use it. Create your GUI
on several panels and use the other layout managers as appropriate to
get the exact effect you want.
The official story from the project leader of the AWT project, as
explained to the Mountain View Java Users' Group on Dec 4 1996, is:
The case has been made and is now accepted that GridBagLayout
is too hard to use for what it offers. GBL will continue to
be supported, and something better and simpler will eventually
be provided as well. This "better GBL" can be used instead of GBL.

Bottom line: nobody has to waste any effort on GBL, there are better
alternatives available now, and more on the way.

2.6 How do you change the font type and size of text in a TextArea?

A. myTextArea.setFont(new Font("FONTNAME", FONTSTYLE, FONTSIZE));
where FONTNAME is the name of the font (eg Dialog or TimesRoman).
FONTSTYLE is Font.PLAIN, Font.ITALIC, Font.BOLD or any
combination (e.g. Font.ITALIC+Font.BOLD).
FONTSIZE is the size of the font, e.g. 12.

2.7 How do you determine the screen dimensions in an applet?

A. Toolkit.getDefaultToolkit().getScreenSize()

2.8 How do you use an image as the background in applets?

A. Create a Panel or Canvas for the background, and draw the image in
the normal way.

2.9 How do you get a MenuBar/Menu in an applet?

A. In your applet's init() method, create a Frame instance
and then attach the Menus, Menubar etc to that frame. You cannot
attach the Menu or a Menubar to an applet directly.

Or get the parent Frame like this:
Container parent = getParent();
while (! (parent instanceof Frame) )
parent = parent.getParent();
Frame theFrame = (Frame) parent;

This second suggestion probably won't work on Macs (where would
the menubar go?) or in some browsers.

In JDK 1.1, just use a popup menu, which isn't attached to a Frame.

-------------------------------------------------------------------------
3. CORE LIBRARIES
3.1 I can't seem to change the value of an Integer object once created.

A. Correct. Integer (Float, Double, etc) are intended as an object
wrapper for a specific value of a number, not as a general purpose
way of shipping a primitive variable around as an Object. If you need
that it's easy enough to create: class general { public int i; }

3.2 How do I print from a Java program?

A. Use the Toolkit.getPrintJob() method
PrintJob pj = getToolkit().getPrintJob((Frame) parent, "test", null);
Graphics pg = pj.getGraphics();
printAll(pg);
pg.dispose();
pj.end();

This feature was introduced with JDK 1.1. A common place to put this
is in the code that handles a button press. There's no easy way to
print in JDK 1.0.2.

3.3 Is there any package in Java to handle HTML?

A. No, Java does not have a core library widget that automatically
formats HTML. At least one person has written one though.
Search at http://www.gamelan.com or http://yahoo.com for details.

3.4 Why don't Dialogs work the way I want them to?

A. Modal dialogs (dialog windows that stay up until you click on them) are
buggy in many browsers and in the 1.0.2 JDK. One bug is that the
dialog is not necessarily put on top when it is displayed.
The modal dialog bugs are fixed in JDK 1.1.

3.5 Where can I find information about the sun.* classes in the JDK?

A. You're not supposed to. Those classes are only to support functions
in the java.* hierarchy. They are not part of the API, and won't be
present in Java systems from non-Sun vendors. Some people have
reverse engineered the code and published an API for these classes but
you use it at your own risk, and it may change without warning.

3.6 How do you read environment variables from with a Java program?

A. Environment variables are not used in Java, as they are not platform
portable. The Mac doesn't have environment variables for example.
Use properties instead. Additionally, on some systems you can set
a property from the command invocation line like this:
java -Dfoo=$foo MyClass (Unix)
or
java -Dfoo=%foo% MyClass (MS-DOS)
This sets the "foo" property to the value of the environment
variable foo.


3.7 How do you use the Date class to display the current time in my
timezone? Date.toString() always uses PST. [jdk 1.1] (Pacific
Standard Time -- the zone covering California where JavaSoft is).

A. To make things easier for debugging Sun has decided that
the toString() method should always use one format,
if you want a different format you should use the new
internationalization routines.

As a Date is stored internally in GMT the obvious choice
for a standard format is in PST time.
As an example of how the new method should work
jdk1.1/src/java/util/Date.java contains the method:

public String toGMTString() {
DateFormat formatter
= new SimpleDateFormat("d MMM yyyy HH:mm:ss 'GMT'",
Locale.US);
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
// + 1 is to work around bug in GregorianCalendar
// XXX - need FIX
// should probably be formatter.format( this );
return formatter.format( new Date(getTime() + 1) );
}

It should be reasonably straight forward to adapt this code
for your prefered format and timezone.


3.8 How do I get Java talking to a Microsoft Access database?

A. Use the JDBC-ODBC bridge. It is not especially challenging to set
up, but it does require painstaking attention to detail. There is
a step-by-step example in the van der Linden text "Just Java 2nd Ed."
Also check the JDBC FAQ listed at the end of this document.

-------------------------------------------------------------------------
4. DISTRIBUTED OBJECTS
4.1 Should I use CORBA in preference to RMI? Or what?

A. If your distributed programs are all in Java, then RMI provides a
simpler mechanism that allows the transfer of code, pass-by-value of
real Java objects, and automatic garbage collection of remote objects.
If you need to connect to legacy C++ (or other language) systems or you
need CORBA-specific services, then CORBA is your choice.

4.2 Why does <my java compiler/IDE/other> hang for a couple of minutes
if if my Windows PC is not dialled up to the Internet?

A. Some of the Java model (e.g. debugging) assumes a socket, but Windows
doesn't always have a TCP/IP stack running which leads to the hang.
There is a URL with help to explain what Windows network config
options you need.
[anyone who knows the URL, please send a note in]

-------------------------------------------------------------------------
5. Java IDIOMS
5.1 How do I convert a String to an int?

A. There are several ways. The most straightforward is:
int i = Integer.parseInt(<String>);
or i = Integer.parseInt(<String>,<int radix>);

Note: there are similar classes for Double, Float, Long, etc.
int i = Integer.valueOf(my_str).intValue();
also works but involves the creation of an extra object.

5.2 How do I convert an int to a string?

A. String s = String.valueOf(i);
or
String s = Integer.toString(i);
or
String s = "" + i; // briefer but may result in extra object allocation.

Note: there are similar classes for Double, Float, Long, etc.

5.3 How do I write to the serial port on my PC using Java?

A. If the port exists as a pathname in the filesystem, you can open
it as a file and read/write. The bigger problem is if you wish to
change the characteristics of the port (e.g. baud rate, parity, etc).
Java currently offers no portable way to do this. You will need to
use a native method, or execute a system command.
At least one company has written a library to drive the port on
Windows 95 and NT. See http://www.sc-systems.com

5.4 How do I append to a file?

A. First, do this:
RandomAccessFile fd = new RandomAccessFile(file,"rw");
fd.seek(fd.length());
Then write using fd.

5.5 How can you send a function pointer as an argument?

Simple answer: use a "callback". Make the parameter an interface
and pass an argument instance that implements that interface.

public interface CallShow { public void Show( ); }

public class ShowOff implements CallShow {
public void Show( ) { .... }

public class ShowMe implements CallShow {
public void Show( ) { .... }

public class UseShow { CallShow callthis;
UseShow( CallShow withthis ) { callthis = withthis; }
void ReadyToShow( ) { callthis.Show( ); }

// in some other class that uses all this stuff:
UseShow use_1 = new UseShow( new ShowOff() );
UseShow use_2 = new UseShow( new ShowMe() );

and then the ReadyToShow() method on use_1 or use_2 will
call the appropriate method, as if you had stored a pointer
to the method.

5.6 How do I execute a command from Java?
How do I do I/O redirection in Java using exec() ?

A. This solution works on Unix platforms using either JDK 1.0.2, or JDK 1.1.
The trick is to use an array of Strings for the command line:

String[] command = {"/bin/sh", "-c", "/bin/ls > out.dat"};

If you don't do this, and simply use a single string, the shell will
see the -c and /bin/ls and ignore everything else after that. It only
expects a single argument after the -c.

import java.io.*;
import java.util.*;

class IoRedirect {
public static void main(String Argv[]) {
try {
String[] command = {"/bin/sh", "-c", "/bin/ls > out.dat"};
Process p = Runtime.getRuntime().exec(command);
p.waitFor();
System.out.println("return code: " + p.exitValue());
} catch (IOException e) {
System.err.println("IO error: " + e);
} catch (InterruptedException e1) {
System.err.println("Exception: " + e1.getMessage());
}
}
}


5.7 OK, how do I read the input from a command?

A. As before, adjusted like this:

BufferedReader pOut
= new BufferedReader(new InputStreamReader(p.getInputStream()));
try {
String s = pOut.readLine();
while (s != null) {
System.out.println(s);
s = pOut.readLine();
}
} catch (IOException e) {
}


5.7 Is it possible to lock a file using Java ?

A. Java does not feature an API to lock a file or regions within a file.
Code that needs to do this must take one of three approaches:
1. implement an advisory locking scheme using features that Java
does have (synchronized methods). This allows you to lock files
against use by other Java code running in the same JVM.
2. Use an atomic operation like "file delete" and have all processes (Java
and non-Java) follow the same protocol: if the file was deleted by you,
you have the lock, and you create the file again to give up the lock.
3. make calls to native code to issue the locking ioctls. This approach
is not portable, but gives you a shot at having your locks respected
by other programs using standard locking ioctls outside Java.

5.8 How do I make the keyboard beep in Java?

A. In JDK 1.1, java.awt.Toolkit has the method beep().
It does not work on NT 4.0 (bug).

5.9 How do I read a String/int/boolean/etc from the keyboard?

In JDK 1.0.2
java.io.DataInputStream in = new java.io.DataInputStream(System.in);
String s = in.readLine();

In JDK 1.1
java.io.InputStreamReader in = new java.io.InputStreamReader(System.in);
String s = in.readLine();

Once you have the token in a String, it is easy to parse it into one
of the other types, as shown earlier in the FAQ.


-------------------------------------------------------------------------
6. MULTI-MEDIA
6.1 Why won't my audio file play?

Java 1.1 and earlier releases use one audio format exclusively. The audio
file must be in .au format, recorded at 8 KHz, mono, in mu-law encoding. If
your audio clip is in a different format (e.g., .wav) or a different
frequency it must be converted to the exact specifications above before
Java can play it.

Search at www.yahoo.com for GoldWave for Win 95, sox for Unix and similar
conversion utilities for other systems. One conversion utility in Java is
at http://saturn.math.uaa.alaska.edu/~hursha

6.2 Does Java support Animated GIFs?

Java 1.0.2 and earlier releases use GIF and JPEG formats, and do not
use the GIF89 animated GIF format. (An animated GIF is one that contains
successive frames of an image, so when they are displayed in quick
sequence the image appears to contain movement).
When you display an animated GIF in Java 1.0.2, you will just get the
first frame. You can use cliprect() with a negative x coordinate to get
other frames from the image.

The advantage of an animated GIF file is that there is only one file
to download, and it is simple to do simple animations. The advantage of
programmatic control over individual frames is that you control the rate
and order of displaying them.

Here's a surprise: JDK 1.1 supports the animated display of animated GIFs.
For simple animations animated GIFs are a lot easier
and lighter-weight than coding an animation explicitly.

-------------------------------------------------------------------------
7. SECURITY

7.1 What is a "trusted applet"?

JDK 1.1 introduced the notion of a "trusted applet" which is one that has
been cryptographically-signed to guarantee its origin and make it tamper
resistant. Trusted applets can be granted more system access privileges
than untrusted applets.


7.2 What is the story with Java and viruses? What is the blackwidow virus?

Java was designed with security in mind. The security features
make it very difficult, probably impossible, to attach a virus (self-
copying code) to a Java applet. As far as is known, there has never been
a Java virus.

There has been mention of a "Java virus" called "BlackWidow" in the media
(it was mentioned in Unigram in late 1996, and obliquely on the RISKS
newsletter in February 1997). A request to the editor of Unigram for more
information brought the answer that there was no more information, it was
just a report of a rumor. As far as is known, this story exists *only*
as rumors reported on by the press. There is no actual Java virus or
blackwidow virus (there are legitimate commercial products of that name).
If anyone has more concrete information about a virus that can attack a
Java applet (again, this is thought to be impossible), please could they
contact the FAQ maintainer with details.

7.3 Why do I get the warning string at the bottom of popup windows "Unsigned
Java Applet Window" in my applets?

A. This is a security feature, to make certain that users can always tell
that a window asking for their password and credit card details (or
whatever) is from an applet. There should be no way to work around
this message.

-------------------------------------------------------------------------
8. FURTHER RESOURCES

8.1 Useful URLS

Latest copy of this FAQ: http://www.best.com/~pvdl/

Other Java resources:
The Java "Hall" of Fame: http://www.apl.jhu.edu/~hall/java/
pretty good glossary: http://oberon.ark.com/~roedy
good JDBC FAQ: http://www.yoyoweb.com/Javanese/JDBC/FAQ.html
tutorial/FAQ (inaccurate/shaky in parts)
http://sunsite.unc.edu/javafaq/javafaq.html

Book lists: http://lightyear.ncsa.uiuc.edu/~srp/java/javabooks.html
http://www.avena.net/~dong/book.htm
http://wwwiz.com/books

Javasoft site: http://java.sun.com

Policy on book references: if you have written a book that you think
answers one of these FAQ questions especially well, please send me a
note of the book, and what your answer is. If I agree it adds value
I'll add a reference to your book in the FAQ section.

8.2 Newgroups
In the process of being reorganized (Feb 1997). Will probably be:

Now Proposed
________ ________
.announce <no change>
.advocacy <no change>
.programmer <no change>
.security <no change>
.setup .help <rename>
.tech .machine <rename>
.databases <add>
.softwaretools <add>
.gui <add>
.beans <add>
.misc <remove>
.api <remove>


-------------------------------------------------------------------------

Acknowledgements:
Original FAQ copyright February 1997 Peter van der Linden

Contributions from: Matt Kennel, Patric Jonsson, Brad Van Tighem, Tony Hursh
Glenn L Vanderburg, Peter Jones, John McDowall, Jim Driscoll, Uday,
Dave Harris, Bill Wilkinson, Tom Valesky, Dan Drake, Giles Thomas,
Mitch Baltuch, Guy Ruth Hammond, Gordon Keith, Jason Brome, Shani Kerr

[<your name here>: send in a suggested FAQ *with the answer*]
----

I am maintaining a FAQ list to address specifically programming issues
(not a general tutorial on Java). Please feel free to mail me entries for it.
Question with answer gets you a credit in the FAQ.
I can be emailed at: lin...@sun.com or pv...@best.com

-- end --

--
Peter van der Linden linden AT sun.com http://www.best.com/~pvdl
-disclaimer-
unless stated otherwise, everything in the above message is personal opinion
and is not an official statement of Fun-Fun Novelty Robot Weapons Inc.

Veselin Vesko Stanic

unread,
Mar 21, 1997, 3:00:00 AM3/21/97
to tony

tony wrote:
>
> I WONDER IF SOMEBODY CAN HELP ME I AM NEW TO JAVA PROGRAMING,BUT i HAVE
> DOWNLOADED & INSTALLED THE JDK1.1 AND FOLLOWED THE INSTALLATION
> INSTRUCTIONS .IE I HAVE SET THE PATH TO
> PATH C:\WINDOWS;C:\WINDOWS\COMMAND;C:\;C:\DOS;C:\JDK1.1\BIN
> SET CLASSPATH=.;C:\JDK1.1\LIB\CLASSES.ZIP
> THE PROGRAM RUNS THE DEMOS OK WITH THE APPLETVIEWER
> BUT WHEN I TRY TO COMPILE A SIMPLE HELLOWORLD PROG LIKE THE
> FOLLOWING
> CLASS HELLOWORLD{
> PUBLIC STATIC VOID MAIN(STRING ARGS[]){
> SYSTEM.OUT.PRINTLN("HELLOWORLD");
> }
> }
> i GET THE FOLLOWING ERROR MESSAGES
> class string NOT FOUND IN TYPE DECLARATION:
> PUBLIC STATIC VOID MAIN(STRING ARGS[])
> &
> UNDEFINED VARIABLE ,CLASS ,OR PACKAGE NAME:SYSTEM
> SYSTEM.OUT.PRINTLN("HELLO WORLD")
>
> THERE ARE ARROWS THAT POINT TO MAIN & SYSTEM IN THE TWO ERROR
> STATEMENTS ABOVE
> I WOULD BE VERY GRATEFUL FOR ANY HELP
>
> REGARDS
> TONY(TO...@ATOMANT.DEMON.CO.UK)
>
try putting
import java.lang.String.*;
import java.io.*;

at the top and bare in mind that Java is case sensitive so Main and main
is not the same.
type

Geraldo do Carmo Thomaz Jr

unread,
Mar 21, 1997, 3:00:00 AM3/21/97
to tony

Are you aware that Capital letters are different from normal letter in
Java ?

0 new messages