• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

First Java program

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I saved my first java program in C:\Program Files\Java\Account.java

To compile compile my source file, im trying to change my current directory C:\Users\sowmyasree> to the directory where my file is located. which is java on the C drive, i type the following command cd C:\java at the prompt and pressed Enter

i got an error message that The system cannot find the path specified please help me,
my OS is windows 7.

i want to learn java at any cost.

 
sree sowmya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
im new to java
to run a java program in windows 7
what software s i have to install and what paths i have to set
please explain briefly as explaining to a kid
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"cd C:\java" should be "cd C:\Program Files\Java".

Check this link to create your first program.
 
sree sowmya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the solution
i successfully entered to the directory

now my problem is with code syntax

Im getting error like line 28 ';' expected and also showing to change 'a' to upper case in ac.ShowData() and when i change it to upper case again telling to change 'A' to lower case.

please help me

below is the code im using



 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags (<-click this link) the next time you want to post code. I've added them for you this time.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Line 27 is lacking a semi-colon.
 
sree sowmya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much i think im troubling you much

but by solving one error im getting other errors

like missing return statement error

it became dream for me to successfully compile a java file
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a lot of typos in your code.
- Void instead of void
- satic instead of static

I hope these are just copy/paste problems. You should get familiar with the Java syntax first.
Read this first.

And post your latest code (UseCodeTags) exactly as it is.
 
Marshal
Posts: 79240
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sree sowmya wrote: . . . I saved my first java program in C:\Program Files\Java\Account.java . . .

Welcome to the Ranch

I am surprised nobody has commented on that. Putting your own work in Program Files is a bad idea. Program Files is a system folder intended for OS use; you should create a folder in My Documents of similar, as I described here. If you uninstall Java and install a new version, there is a risk of the entire folder being deleted and all your work vanishing mysteriously.

You would have done better to start a new discussion for each question.
 
sree sowmya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I thank you both for taking your time to help me

as suggested i have changed my files to D directory instead of in programming files.

now the problem is when the files are in C drive i was able to compile my .java file using javac Hello.java
i created a folder in D with name as java and saving in that my programs.

D:\java> is my directory now

now im getting an error message as "javac is not recognized as internal or external command"

my PATH is C:\Program Files\Java\jdk1.6.0_23\bin\javac
CLASSPATH is C:\Program Files\Java\jdk1.6.0_23\lib
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One other thing someone should mention.

Writing 30 lines of code before compiling it is a BAD idea. You will tend to get lots of error all over the place. You fix one, and the compiler returns a bunch of new ones. You get frustrated and want to smash your computer.

Never never never never write more than 2-3 lines before you compile. If you write 2 lines and get a "missing semi-colon" error, you know what two lines to focus in on. If you write 2 lines and get a list of 20 errors (yes, it can happen), you again know where to focus your attention.

If you write 30 lines and compile, it can be a needle in a haystack finding the problem. Yes, the compiler tries to tell you where the error is, but as you learned, it isn't always correct.
 
sree sowmya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No no i have changed the program now im working on following code please help me from past 10 hours im breaking my head i dieing to see the out put of my first java program.


 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We can't help you if you don't tell us what the problem is...
 
sree sowmya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i posted the problem briefly in the previous post but still here is the problem


im getting an error message as "javac is not recognized as internal or external command"


my PATH is C:\Program Files\Java\jdk1.6.0_23\bin\javac
CLASSPATH is C:\Program Files\Java\jdk1.6.0_23\lib
 
Ranch Hand
Posts: 32
Eclipse IDE Tomcat Server Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try Setting the path as

C:\Program Files\Java\jdk1.6.0_23\bin;

and restart the system. Sometimes closing and opening the Cmd works.

Hope this helps
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sree sowmya wrote:i posted the problem briefly in the previous post but still here is the problem


sorry - i missed that. I think you and I were both posting at about the same time.

your path shouldn't have the "javac" on the end. it should stop at the "...\bin". for example, here it my path, with my java dir in bold:

C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Lenovo;C:\Program Files\Lenovo\Client Security Solution;C:\Program Files\Common Files\Ulead Systems\MPEG;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;C:\Program Files\Java\jdk1.6.0_23\bin;C:/Python27;c:\sqlite;c:\unixtools;C:\Program Files\Novell\GroupWise

Note that if you have an open cmd window, you will have to close it and open a new one. You should not have to restart the entire box.
 
sree sowmya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much the javac command compiled successfully.

now problem is when running it I have attached a screen shot of my command prompt please check it below

error-message.jpg
[Thumbnail for error-message.jpg]
please check it
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post error messages as text (copy and paste the text) instead of as an image.

You need to make sure that the directory that contains the Hello.class file is in the classpath. The easiest way to do that is to put "." (the current directory) on the classpath with the "-cp" option when you run your program:

java -cp . Hello

Note: Make sure the CLASSPATH environment variable is not set. If it's not set, Java automatically uses the current directory as the classpath, so that you would not have to add the "-cp ." to the command.
 
sree sowmya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But i already set my class path
CLASSPATH is C:\Program Files\Java\jdk1.6.0_23\lib

should i delete it,
 
sree sowmya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thankyou soooooo much every one i got my first java program output
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sree sowmya wrote:But i already set my class path
CLASSPATH is C:\Program Files\Java\jdk1.6.0_23\lib

should i delete it,


If the CLASSPATH is set, the java executable ONLY LOOKS in the directories listed there for your .class files. So unless your Hello.class file is in the above directory, it can't find it.

There are several ways to solve this.

a) delete your CLASSPATH variable (and then open a new cmd window)
b) add a dot to your CLASSPATH as another directory - java will then look in your 'current' directory. You would need to cd to wherever your Hello.class file is first.
c) try "java -cp . Hello", assuming you are already in the directory where your Hello.class file is.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sree sowmya wrote:But i already set my class path
CLASSPATH is C:\Program Files\Java\jdk1.6.0_23\lib

should i delete it,


Yes, you should delete it. There is no need to put the directory C:\Program Files\Java\jdk1.6.0_23\lib in the classpath - it's not a directory where Java class files are stored.
 
sree sowmya
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all the support i got

i have changed my class path o where the .class file is stored hat is D:\java

Now Im able to compile my program successfully


thank youuuuuuuuuuuu I feel this is the best blog and the best people i ever seen
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ankita Alwani,
Your post was moved to a new topic.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sree sowmya,
Your post was moved to a new topic.
 
reply
    Bookmark Topic Watch Topic
  • New Topic