• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

compiling this java program

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

how should I compile this program.
trying javac BeerExpert.java gives error.
 
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, use code tag when showing code. It's much easier to read.
Second, what is the error that you are getting?

Gary
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UseCodeTags, when you post coding. Where did you get this code? Where is your main method?
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello ajit
save the program as BeerExpert.java
and compile the program as:
javac -d . BeerExpert.java
 
Marshal
Posts: 80767
488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this code i have included Generics with this.So now it should Compile fine



Check it out by compiling.
 
ajit chaudhary
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks to everybody.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are Welcome
and Also Welcome to JavaRanch
 
ajit chaudhary
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ajit chaudhary, are you learning java? If so, this book isn't for java beginners. Use Head First Java.
 
ajit chaudhary
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 80767
488
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlets is an advanced Java topic. At least, I think that is what was meant.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!



 
Ninad Kuchekar
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!



 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22854
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't use colours like that. Especially colours that make it harder to read your post.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic