• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java and the questions of an Greehorn ;)  RSS feed

 
holger alberty
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there everyone ;) !

Okay have a simple question.Yesterday i compiled several codes i've written on base of a book from the "Head first" series. (O'Reilly 2nd edition),done everything over the cmd panel,written my code in the normal standard texteditor of win7. saved everything under ".java".

So,when i begin in cmd i usually type in the section/folder where my java lies (comand: cd folder) then i write: "javac MyProgram.java",causing how i understand it,the JVM to produce another version of my code compiled,is that right til this point ? i don't have that much choice for the moment,in what to open that code,so i can give it out on the texteditor again,firefox, the Notepad,and wordeditor...thing is,i see no change in what the programms are writing and i think it should differ from the original,right ?. In my understanding,the output should just show me the "clean" message (this time no massage ^^).BUT it doesn't...so what would you recommend ?!

I know,some,if not all people will go like ("oh,man...don't even start asking THIS") cause,it's obviouse for people working every day in java,but here it is ^^
so please help me ;) !

Cheers and greetings Holger
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
holger alberty wrote:Hello there everyone ;) !

Okay have a simple question.Yesterday i compiled several codes i've written on base of a book from the "Head first" series. (O'Reilly 2nd edition),done everything over the cmd panel,written my code in the normal standard texteditor of win7. saved everything under ".java".

So,when i begin in cmd i usually type in the section/folder where my java lies (comand: cd folder) then i write: "javac MyProgram.java",causing how i understand it,the JVM to produce another version of my code compiled,is that right til this point ? i don't have that much choice for the moment,in what to open that code,so i can give it out on the texteditor again,firefox, the Notepad,and wordeditor...thing is,i see no change in what the programms are writing and i think it should differ from the original,right ?. In my understanding,the output should just show me the "clean" message (this time no massage ^^).BUT it doesn't...so what would you recommend ?!

I know,some,if not all people will go like ("oh,man...don't even start asking THIS") cause,it's obviouse for people working every day in java,but here it is ^^
so please help me ;) !

Cheers and greetings Holger


Hi and welcome to Java ;)

You're right, when you use javac, your program text (the .java file) is compiled, and a class file is created from it. For example, if you compile "MyProgram.java", the compiler creates the file "MyProgram.class". You can run this program now by using the java command. The typical order of things is:

- write a java program (source text) in your editor, and save it as a .java file, for example your MyProgram.java
- compile the program: javac MyProgram.java, giving you a .class file (MyProgram.class)
- run the compiled program: java MyProgram (note that you do not specify the ".class" here)
 
holger alberty
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey there D.Ogranos ! ;)

thanks for the fast responding !,uhm when i've done what you've written f.e :



so ?! what now ?

Okay,it sais as follows if i run : java MooseGreetings

.
.
.
several "java-things" not found



(is there ANY way of copy/paste from my msdos cmd to this board ?)
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

You need to compile the source code (in the .java file) to a .class file before you can run it.

Compiling is done with javac, the Java compiler. Try compiling it with: javac MooseGreetings.java

If you can do this without getting errors, try to run it: java MooseGreetings

Have a look at The Java Tutorials. The page About the Java Technology explains how the process works. The Hello World tutorial explains how to write, compile and run your first Java program, with hints about common problems and their solutions.

About copying text from the Windows command prompt, see: Copy To the Clipboard From the Windows Command Prompt
 
holger alberty
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Jesper,

thanks to you,too !

i'll look at your links right now

it's not about the code i think it's about the right directives where my java ist installed ^^..cause i've already compiled this.

i've written:

1.



2. saved that as MooseGreetings.java
3. compiled it via cmd,saying : javac MooseGreetings.java (worked cause the machine has created a CLASS file of MooseGreetings)
4. tried the comand : java MooseGreetings (if i do this,it sais that there is no class to be found,which is called MooseGreetings and that it's not going to finish its work and shut down working on this programcode)
5. and the other way around: MooseGreetings.java (this ends in giving it out on my browser,the whole code without exception)


Okay,i've erased everything what i've done til now in the directory and started anew (regarding the instructions of the "Hello World" doc).

everything is fine and works as it should until :



Run the Program

In the same directory, enter the following command at the prompt:

java HelloWorldApp



This is where it sais again that it can't find the class althpugh it has created one in the same directory °°
 
Roberto Perillo
Bartender
Posts: 2273
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, Holger!

Well champ, it may be a classpath problem. Please try running it with java -cp . HelloWorldApp in the directory the .class file was produced. The "." indicates that the current directory should be included in your classpath.
 
holger alberty
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
^^ Hey there folks ...i've erased the classpath and pasted my current java directive ^^ now everything works ;)

Thanks again ! if i'm stuck again i'll return ;) hope that's a little longer then next few moments ;)
Cheers and Greetings
Holger
 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
holger alberty wrote:(is there ANY way of copy/paste from my msdos cmd to this board ?)


Yes. open a command prompt. right-click on the (normally) blue bar at the top top, and select "properties". There should be a 'quickEdit mode' checkbox. I personally "apply it to the shortcut that opened this window".

You can then click-n-drag to highlight a rectangle. Hit 'enter', and it will copy it into your buffer. you can then cntl-v to paste it into just about anything else you like.
 
holger alberty
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According the "Beer Song" based on the example in "HeadFirst Java 2nd Edition.

this is my code i have windows 7 and i'm pretty sure, that's exactly what's printed in the example,prob is it sais i have errors in different places with differetnissues,BUT that can't be,would someone please be so kind to help a little ?

CODE:
---------------------------------------------------------------------------------------
public class BierLied {
public static void main(String[] args){
int bierAnzahl = 99;
String wort ="Flaschen";
while (bierAnzahl > 0){
if (bierAnzahl == 1){
wort ="Flasche";
}
System.out.printIn("bierAnzahl + " " + wort + "Bier im Kuehlschrank");
System.out.printIn("bierAnzahl + " " + wort + "Bier");
System.out.printIn("Hol eine raus.");
System.out.printIn("und lass sie rumgehen.");
bierAnzahl = bierAnzahl - 1;
if (bierAnzahl > 0){
System.out.printIn(bierAnzahl + "" +wort+ "Bier im Kuehlschrank");
}else{
System.out.printIn("Kein Bier mehr im Kuehlschrank");
}
}
}
}
---------------------------------------------------------------------------------------

i'd be grateful for any hint !! thanks in advance !
Moonfox


..i tried a few things and it seams that my commandline usually doesn't like "." (in syntaxes like: "System.out.printIn("..."); ..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!