aspose file tools *
The moose likes Beginning Java and the fly likes compiling this java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compiling this java program" Watch "compiling this java program" New topic
Author

compiling this java program

ajit chaudhary
Greenhorn

Joined: May 10, 2010
Posts: 8

how should I compile this program.
trying javac BeerExpert.java gives error.
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 161

First, use code tag when showing code. It's much easier to read.
Second, what is the error that you are getting?

Gary


star chaser..
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

UseCodeTags, when you post coding. Where did you get this code? Where is your main method?


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11500
    
  16

I added the code tags for you, which makes it much easier to read.

When you try "javac BeerExpert.java", it gives you some kind of message. It is actually telling you why it failed. There are many reasons, but we have no idea what might be the real one without that information. And it's pointless for us to guess. It could be anything from you don't have the JDK installed to your path is wrong to your classpath is wrong to the code has syntax errors to about a hundred other things.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
sharma sachin
Greenhorn

Joined: Nov 13, 2009
Posts: 24
hello ajit
save the program as BeerExpert.java
and compile the program as:
javac -d . BeerExpert.java
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40079
    
  28
Since it's supposed to be beginner's code, try commenting out the package declaration.

It's from Head First Java, surely?
ajit chaudhary
Greenhorn

Joined: May 10, 2010
Posts: 8
this code is from the book "HEAD FIRST SERVLETS AND JSP".

The class file is created , but the following message appears in the windows command prompt:

note: BeerExpert.java uses unchecked or unsafe operations.
note:Recompile with -Xlint:unchecked for details.

what does this mean?
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

ajit chaudhary wrote:this code is from the book "HEAD FIRST SERVLETS AND JSP".

The class file is created , but the following message appears in the windows command prompt:

note: BeerExpert.java uses unchecked or unsafe operations.
note:Recompile with -Xlint:unchecked for details.

what does this mean?



This means that your code Compiles with warning..
Because, List and ArrayList comes in Generics now.
and you are using it without a Generics so it is compiling with warning.
Also Your code will run fine,try that and you can ignore this

SCJP6.0,My blog Ranchers from Delhi
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

Check this code i have included Generics with this.So now it should Compile fine



Check it out by compiling.
ajit chaudhary
Greenhorn

Joined: May 10, 2010
Posts: 8
thanks to everybody.
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

You are Welcome
and Also Welcome to JavaRanch
ajit chaudhary
Greenhorn

Joined: May 10, 2010
Posts: 8


while compiling it,the following error message comes :

package com.example.model does not exist.


where does the compiler look for this package? I have just created this class file in the previous code given here.
what should I do?
again this code is from the same book
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

ajit chaudhary, are you learning java? If so, this book isn't for java beginners. Use Head First Java.
ajit chaudhary
Greenhorn

Joined: May 10, 2010
Posts: 8
I am reading both these books "head first java" and "head first servlets and jsp" together.

could you help me with this issue meanwhile.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40079
    
  28
Servlets is an advanced Java topic. At least, I think that is what was meant.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Campbell Ritchie wrote:Servlets is an advanced Java topic. At least, I think that is what was meant.


Is it advanced java technology or advanced java? I think, it's a technology solved by Java?
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16
Abimaran Kugathasan wrote:
Campbell Ritchie wrote:Servlets is an advanced Java topic. At least, I think that is what was meant.


Is it advanced java technology or advanced java? I think, it's a technology solved by Java?


Whatever it is, it's advanced enough that anybody studying it should know what the classpath is and how to set it, which it appears Ajit doesn't.


Joanne
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Joanne Neal wrote:

Whatever it is, it's advanced enough that anybody studying it should know what the classpath is and how to set it, which it appears Ajit doesn't.

Agreed! But, servlet, JSP, EJB are technologies based on java?
Ninad Kuchekar
Ranch Hand

Joined: Jan 05, 2010
Posts: 64
Hi Ajit,

Sharma Sachin wrote:
save the program as BeerExpert.java
and compile the program as:
javac -d . BeerExpert.java


To explain in detail, the '-d' switch is used to notify about the place where the class files should be placed and the succeeding '.' denotes the path where the class files are placed(in this case, '.' specifies the current directory) .
Since your class specifies a package name, the above command will create the appropriate directory structure and place the class files in it.

I hope I have not added to your confusion.

This link might explain in a better way:
javac - Java Programming Language Compiler

Welcome to the Ranch!




Don't walk as if you rule the world, walk as if you don't care who rules it...
Ninad Kuchekar
Ranch Hand

Joined: Jan 05, 2010
Posts: 64
Hi Ajit,

Sharma Sachin wrote:
save the program as BeerExpert.java
and compile the program as:
javac -d . BeerExpert.java


To explain in detail, the '-d' switch is used to notify about the place where the class files should be placed and the succeeding '.' denotes the path where the class files are placed(in this case, '.' specifies the current directory) .
Since your class specifies a package name, the above command will create the appropriate directory structure and place the class files in it.

I hope I have not added to your confusion.

This link might explain in a better way:
javac - Java Programming Language Compiler

Welcome to the Ranch!



Virendrasinh Gohil
Ranch Hand

Joined: Jun 09, 2004
Posts: 46
ajit chaudhary wrote:how should I compile this program.
trying javac BeerExpert.java gives error.


Ajit,

The problem started with first step itself. When you were trying to compile your BeerExpert.java. When you say something like: It means, you have to put your java file in directory name com/example/model. Which means, you should have com/example/model/BeerExpert.java structure.

Now, please go to HeadFirst Java book and see how to compile your code inside a package (in package topic)

When you will compile this code, your class file will reside in same directory with .class extension. (Assuming you have not specified -d option while compiling) which means, you will have com/example/model/BeerExpert.class.

Now your servlet class (event if it's a servlet, it's class after all) has package as : So, you know where to put this class into and how to compile this class. (I am sure you will get compilation error for not finding javax.servlet.* package as you don't have classpath defined. And to know how to set classpath, you have to read Java (head first java) first. That is what exactly everybody is saying in this thread that you have to first read Head First Java and then read Head First Servlet and JSP as Servlet is advance topic).

Shortcuts won't help for sure. Please do not jump. Go step by step. That is more fun.
ajit chaudhary
Greenhorn

Joined: May 10, 2010
Posts: 8
I tried this and it worked fine:

javac -d ../classes com/example/web/BeerSelect.java

while compiling it from beer-v1/src folder.in this way the compiled class file automatically goes to classes/com/example/web folder.

I referred the head first java book.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19799
    
  20

Please don't use colours like that. Especially colours that make it harder to read your post.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compiling this java program