Misplaced "s"

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 2975 Views - Last Post: 20 December 2012 - 08:04 AM Rate Topic: -----

#16 extremeblueness  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 186
  • Joined: 22-October 12

Re: Misplaced "s"

Posted 08 December 2012 - 06:31 AM

I need the IDE, mainly because I never learned to compile and execute. My code books never tought me how.
Was This Post Helpful? 0
  • +
  • -

#17 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 8034
  • View blog
  • Posts: 13,747
  • Joined: 19-March 11

Re: Misplaced "s"

Posted 08 December 2012 - 09:55 AM

Is that all that's stopping you?

If you have the jdk installed, javac is the command to invoke the compiler. For a simple program consisting of one or several source files in a directory, the easiest thing is to just type

> javac MyMainClass.java


at the command prompt, where MyMainClass is the name of the class that has your main method. The compiler will deal with the dependencies and compile the classes that it needs. (compiling the main class will therefore compile everything that the main class needs to run)

There will likely be some error output if you've just written the class. The error output is quite informative, use it to get rid of the errors. When the compiler returns without output, you've successfully compiled.

> java MyMainClass

will run that class, starting from the main() method. Note that you're

not doing

> java MyMainClass.java

or

> java MyMainClass.class

Java knows that a public class must be declared in a file with the same name as the class, so if you tell it to run a class Foo, it's going to look for it in a file called Foo.class, so you don't need to give it the .class extension. As for the source file, to the virtual machine, that's just a bunch of text - the vm can't do anything with it at all.

So that's really all there is to it. For more complicated programs, there are some complications, but you'll ind those are easiest to manage with a tool like ant. For now, this will get you there.

This post has been edited by jon.kiparsky: 08 December 2012 - 09:57 AM

Was This Post Helpful? 0
  • +
  • -

#18 extremeblueness  Icon User is offline

  • D.I.C Head

Reputation: 16
  • View blog
  • Posts: 186
  • Joined: 22-October 12

Re: Misplaced "s"

Posted 08 December 2012 - 03:48 PM

Hmm... I think I'm gonna have to look for information on how to create a directory.
Was This Post Helpful? 0
  • +
  • -

#19 Cheribasa  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 212
  • Joined: 11-December 12

Re: Misplaced "s"

Posted 20 December 2012 - 08:04 AM

View Postextremeblueness, on 25 October 2012 - 07:33 AM, said:

It took me an hour because BlueJ, the program I work with to work with Java, is stupid, and wouldn't point out my mistake.


Is that so? I use Bluej; and it always finds my syntax mistakes. Maybe such didn't exist in earlier versions?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2