PDA

View Full Version : Java question


Nightfire
09-04-2002, 12:21 AM
I'm wanting to have a go at java. I've been trying to get the SDK from the java sun site, but everytime I finally download it, it gives me an error, about it being corrupt. So, can I use any other java programs that does the same as this SDK program? As you can see, I don't know what it does, I just read that I need it to compile applets.

Nightfire
09-04-2002, 07:44 PM
Ok, I got the jdk1.1.8 but every time I'm trying to compile it, it's saying:


error: Can't read: HelloWorldApp.java
1 error


Here's the command I'm typing in DOS:


C:\>jdk1.1.8\bin\javac HelloWorldApp.java


I put the HelloWorldApp.java file in the bin directory too. Can anyone help me?

My java code is:


public class HelloWorldApp {
public static void main(String[] args) {
// Display "Hello World!"
System.out.println("Hello World!");
}
}

Nightfire
09-05-2002, 03:20 AM
Nevermind, I'll just stick to php

Spookster
09-05-2002, 11:52 PM
Try this:


class HelloWorldApp {
public static void main(String[] args) {
// Display "Hello World!"
System.out.println("Hello World!");
}
}


To compile:

javac HelloWorldApp.java

To run it:

java HelloWorldApp


And yes you should put that file in the bin directory unless you have set up classpaths to point to somewhere else.

Nightfire
09-06-2002, 12:07 AM
Thanks :D that worked. What does the "public" mean on the first line?

hairynugs6382
09-06-2002, 05:39 PM
is it just me or is it similar to c++
java looks almost the same i did not know that java was even compiled language!

bcarl314
09-06-2002, 05:52 PM
Originally posted by Nightfire
Thanks :D that worked. What does the "public" mean on the first line?

Public means that the methods within the class can be accessed by other classes.

Nightfire
09-06-2002, 06:50 PM
Ahh, ok :) Thanks

Spookster
09-06-2002, 08:21 PM
Yes "public" is an access identifier. You also have "private". These come in handy when creating packages and instantiable classes where you only want to give access to certain methods or variables.

Yes Java is a compiled language; not to be confused with Javascript. And yes Java is very similar to C++ as far as syntax.