very frustrated Java programmer

R

Randy O'Bright

Hello,

I'm an intermediate/advanced level programmer taking a 200 level intro
java course, but I am having an extremely difficult time with what
could be a very simple problem. The following program, should write
"hello world" to the console when it is run:

public class HelloWorld {
public void main(String[] args) {
System.out.println("hello world");
}
}


however, it's not, and I'm wasting valuable hours trying to figure out
why the anal java vm doesn't like it. My prof claimed that java was a
flexible and powerful language, but personally, I'm not getting that
impression so far (at least as far as flexibility goes)...

note: a speedy response (aka, before 9:00 am EST monday morning) would
be appreciated.

TIA,
Randy O'Bright
 
A

Adrian

Randy O'Bright said:
Hello,

I'm an intermediate/advanced level programmer taking a 200 level intro
java course, but I am having an extremely difficult time with what
could be a very simple problem. The following program, should write
"hello world" to the console when it is run:

public class HelloWorld {
public void main(String[] args) {
System.out.println("hello world");
}
}


however, it's not, and I'm wasting valuable hours trying to figure out
why the anal java vm doesn't like it. My prof claimed that java was a
flexible and powerful language, but personally, I'm not getting that
impression so far (at least as far as flexibility goes)...

Does it run at all? What environment are you in?

ExpatEgghead
 
S

Silvio Bierman

Randy O'Bright said:
Hello,

I'm an intermediate/advanced level programmer taking a 200 level intro
java course, but I am having an extremely difficult time with what
could be a very simple problem. The following program, should write
"hello world" to the console when it is run:

public class HelloWorld {
public void main(String[] args) {
System.out.println("hello world");
}
}


however, it's not, and I'm wasting valuable hours trying to figure out
why the anal java vm doesn't like it. My prof claimed that java was a
flexible and powerful language, but personally, I'm not getting that
impression so far (at least as far as flexibility goes)...

note: a speedy response (aka, before 9:00 am EST monday morning) would
be appreciated.

TIA,
Randy O'Bright

Nothing wrong with the code. You are either compiling it wrong or running it
wrong.

Silvio Bierman
 
J

Jeen Broekstra

Randy said:
I'm an intermediate/advanced level programmer taking a 200
level intro java course, but I am having an extremely
difficult time with what could be a very simple problem. The
following program, should write "hello world" to the console
when it is run:

public class HelloWorld {
public void main(String[] args) {
System.out.println("hello world");
}
}


however, it's not, and I'm wasting valuable hours trying to
figure out why the anal java vm doesn't like it.

It's the declaration of your main method. It needs to be static
to indicate that it is a class method, not an instance method.
My prof claimed that java was a flexible and powerful language,
but personally, I'm not getting that impression so far (at
least as far as flexibility goes)...

In a way, it depends a bit on what you define a flexible language
to be. There's the C++ kinda flexibility, which basically is a
"the programmer knows best" attitude. It allows you to do
virtually anything (cast any object to pretty much any other,
operator overloading, etc. etc.), but the potential for
sloppy, buggy programs is much higher. Java is slightly stricter
in what it allows (strong typing, for example), but the advantage
is that many potential bugs are flushed out at compile-time. Add
to that the _very_ nice exception handling, the fact that memory
allocation is handled for you, and you don't have to worry about
pointers, and you have a powerful and flexible tool.

Oh, and it's platform-independent of course :)

Jeen
 
R

Ravi Shankar

Hi all,

Please make main as static!!!

public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello world");
}
}

Save it in a file "HelloWorld.java", then compile and run!!

Regards,
Ravi
 
D

david m-

I think you'll find that main needs to be a class method rather than an
instance method.

david m.
 
D

david m-

An intelligent guess would suggest that the application is started by
calling main thus

HelloWorld.main()

rather than

HelloWorld app = new HelloWorld();
app.main();

i.e. it doesn't create an instance of the HelloWorld class.

david m.

david m- said:
I think you'll find that main needs to be a class method rather than an
instance method.

david m.

Randy O'Bright said:
Hello,

I'm an intermediate/advanced level programmer taking a 200 level intro
java course, but I am having an extremely difficult time with what
could be a very simple problem. The following program, should write
"hello world" to the console when it is run:

public class HelloWorld {
public void main(String[] args) {
System.out.println("hello world");
}
}


however, it's not, and I'm wasting valuable hours trying to figure out
why the anal java vm doesn't like it. My prof claimed that java was a
flexible and powerful language, but personally, I'm not getting that
impression so far (at least as far as flexibility goes)...

note: a speedy response (aka, before 9:00 am EST monday morning) would
be appreciated.

TIA,
Randy O'Bright
 
S

Silvio Bierman

Silvio Bierman said:
Randy O'Bright said:
Hello,

I'm an intermediate/advanced level programmer taking a 200 level intro
java course, but I am having an extremely difficult time with what
could be a very simple problem. The following program, should write
"hello world" to the console when it is run:

public class HelloWorld {
public void main(String[] args) {
System.out.println("hello world");
}
}


however, it's not, and I'm wasting valuable hours trying to figure out
why the anal java vm doesn't like it. My prof claimed that java was a
flexible and powerful language, but personally, I'm not getting that
impression so far (at least as far as flexibility goes)...

note: a speedy response (aka, before 9:00 am EST monday morning) would
be appreciated.

TIA,
Randy O'Bright

Nothing wrong with the code. You are either compiling it wrong or running it
wrong.

Silvio Bierman

Correction,

You could not run it since main is not static, as one of the other
respondents did not overlook.

Silvio Bierman
 
S

Sudsy

Randy said:
Hello,

I'm an intermediate/advanced level programmer taking a 200 level intro
java course, but I am having an extremely difficult time with what
could be a very simple problem. The following program, should write
"hello world" to the console when it is run:

public class HelloWorld {
public void main(String[] args) {

public static void main(String[] args) {

The static modifier is absolutely essential. While Java is
somewhat flexible, it doesn't tolerate ommissions of keywords.
But then most other languages don't either... ;-)
 
A

Andrew Thompson

....
public class HelloWorld { .....
however, it's not, and I'm wasting valuable hours trying to figure out

We could waste valuable hours tring to figure out
what your error is, since you did not supply it.
why the anal java vm doesn't like it.

My crystal ball is saying 'NoClassDefFound',
and if the aether is not too foggy and I read
that right, try..

java -cp . HelloWorld

HTH
 
S

Sudsy

Andrew said:
...



We could waste valuable hours tring to figure out
what your error is, since you did not supply it.




My crystal ball is saying 'NoClassDefFound',
and if the aether is not too foggy and I read
that right, try..

Your crystal ball is foggy. Too many complimentary beers, I'd guess...
(ROTFLMAO!)
 
A

Andrew Thompson

| Andrew Thompson wrote:
.....
| > My crystal ball is saying 'NoClassDefFound',
| > and if the aether is not too foggy and I read
| > that right, try..
|
| Your crystal ball is foggy. Too many complimentary beers, I'd
guess...
| (ROTFLMAO!)

Rome beer good. (burp)
...id wuz worth it! (..hic!)

A.
 
M

Manuel Perdigão

public class HelloWorld {
public static void main(String[] args) {
System.out.println("hello world");
}
}
 
M

Manuel Perdigão

public class HelloWorld {
public staic void main(String[] args) {
System.out.println("hello world");
}
}
 
L

Larry Coon

Randy said:
I'm an intermediate/advanced level programmer taking a 200 level intro
java course, but I am having an extremely difficult time with what
could be a very simple problem. The following program, should write
"hello world" to the console when it is run:

public class HelloWorld {
public void main(String[] args) {
System.out.println("hello world");
}
}

however, it's not, and I'm wasting valuable hours trying to figure out
why the anal java vm doesn't like it. My prof claimed that java was a
flexible and powerful language, but personally, I'm not getting that
impression so far (at least as far as flexibility goes)...

note: a speedy response (aka, before 9:00 am EST monday morning) would
be appreciated.

Others have already commented on the problem with your code,
but I have additional comments on what you asked and the way
you asked it. Use, ignore or discard as you wish, but it may
come in handy the next time you need to ask a question.

Someone once wrote an article called "How to ask questions the
smart way," (see bottom) in which he described common mistakes
people make when posting on Usenet looking for help, and
explained why those were mistakes. Your post committed a good
number of them:

-- If you're an advanced programmer (even though you qualified
it as "intermediate/advanced") you should be able to work through
getting a "hello world" program working, in pretty much any
language, on pretty much any system. If you can't, it's an
important skill to acquire, but you're dismissing it as a "waste
of valuable time." As a sometimes university instructor myself,
I care more that my students acquire problem solving skills than
I care about their understanding of the syntactic idiosyncrasies
of a particular language, because with the former you can work
through the latter. So on the contrary, it's not a waste of
time, it's probably the most valuable way you CAN spend your
time. And even if it is a waste of time, you can't learn the
language without learning what the compiler expects. (Besides,
many readers, when seeing you describe yourself as advanced and
seeing what problem you're having, will conclude that you're
probably full of yourself.)

-- Cardinal mistake: "This doesn't work" without any indication
of what it IS doing and what you've tried. The commands you
ran, the error messages you got, SOMETHING so people don't have
to read your mind....

-- What you wrote: "I'm wasting valuable hours trying to figure
out why the anal java vm doesn't like it." What people read:
"I want you to use YOUR time solving my problem (for free)
because my time is more valuable than yours. Oh, and it's not
MY fault, it's the COMPILER'S fault for being too anal."

-- "My prof claimed that java was a flexible and powerful
language, but personally, I'm not getting that impression so
far (at least as far as flexibility goes)..." Umm, I think
Java's flexibility is related to factors other than how easy
it is to get a "hello world" program working for someone who
doesn't want to take the time to learn the language.

-- What you wrote: "a speedy response (aka, before 9:00 am
EST monday morning) would be appreciated." How that's read:
"Not only do I want you to use your time (as I said, mine's
too valuable), but I want you to do it on MY schedule too."
And frankly, a student's concept of urgency is likely to
differ from others' concept of urgency. Will lives, jobs
and/or millions of dollars be lost if you don't have an
answer by 9:00 AM Monday? For some people who may be
reading your post, that's what urgency means.

Sorry if this comes off as hostle or arrogant. You can read
the full article here:
http://www.catb.org/~esr/faqs/smart-questions.html
 
S

Sudsy

Larry said:
-- What you wrote: "I'm wasting valuable hours trying to figure
out why the anal java vm doesn't like it." What people read:
"I want you to use YOUR time solving my problem (for free)
because my time is more valuable than yours. Oh, and it's not
MY fault, it's the COMPILER'S fault for being too anal."

You make some very good points. Did you notice that the only
thing missing from this thread is the OP saying "thanks for
the help"? Interesting...
-- "My prof claimed that java was a flexible and powerful
language, but personally, I'm not getting that impression so
far (at least as far as flexibility goes)..." Umm, I think
Java's flexibility is related to factors other than how easy
it is to get a "hello world" program working for someone who
doesn't want to take the time to learn the language.

Always easier to blame shoddy work on the tool rather than the
person wielding the tool...
-- What you wrote: "a speedy response (aka, before 9:00 am
EST monday morning) would be appreciated." How that's read:
"Not only do I want you to use your time (as I said, mine's
too valuable), but I want you to do it on MY schedule too."
And frankly, a student's concept of urgency is likely to
differ from others' concept of urgency. Will lives, jobs
and/or millions of dollars be lost if you don't have an
answer by 9:00 AM Monday? For some people who may be
reading your post, that's what urgency means.

There's been a lot of that recently. While I can understand
that people are sometimes under time pressures, the nature of
usenet is to solicit considered responses. If they arrive in
a timely manner then you're ahead of the game; it should not
be an expectation.
Sorry if this comes off as hostle or arrogant. You can read
the full article here:
http://www.catb.org/~esr/faqs/smart-questions.html

Not at all! While many of us are willing to provide assistance,
precious few (except at certain forward-thinking firms) are
paid for the time we spend here.
If something is sufficiently complex and/or time-sensitive then
the posters should seriously consider contracting the services
of professionals.
They'd pay for a plumber wouldn't they?
 
X

xarax

/snip/
There's been a lot of that recently. While I can understand
that people are sometimes under time pressures, the nature of
usenet is to solicit considered responses. If they arrive in
a timely manner then you're ahead of the game; it should not
be an expectation.
/snip/

Not at all! While many of us are willing to provide assistance,
precious few (except at certain forward-thinking firms) are
paid for the time we spend here.
If something is sufficiently complex and/or time-sensitive then
the posters should seriously consider contracting the services
of professionals.
They'd pay for a plumber wouldn't they?

Actually, there have been a few posters that offered
to pay someone to do their homework assignments. If
lives, dollars, or someone else's job is at stake, then
I could see paying for professional services (but why
come here for such services). OTOH, if the poster's job
or his grades are at stake, then I would blow him off. I
don't want an undisciplined or uneducated person to be
working in the industry. Too many people out of work now
to have what few remaining jobs go to people who don't
really know what they are doing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top