• Post Reply Bookmark Topic Watch Topic
  • New Topic

OCA Study Guide, Ch1 - Writing a main() Method  RSS feed

 
Melo Mashabane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What tools am we to use for the below? An IDE or Notepad and the command tool?

On page 6 (of the above reference) it instructs to compile and execute the below code into a file called Zoo.java



and execute the following.

$ javac Zoo.java
$java Zoo

 
Zachary Griggs
Ranch Hand
Posts: 83
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It sounds like they want you to use the command line with a notepad document. javac is the compilation command, and java is the run command. You'll first need to set up the environmental variables in the command line to point to the jdk, but the book probably told you how to do that if they're asking for command line use.
 
Melo Mashabane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Zachary Griggs Thank you for that. When I use the command prompt I get the following error message:

'$' is not recognized as an internal or external command, operable program or batch file.

When I remove the $ sign I get the below message.

'javac' is not recognized as an internal or external command, operable program or batch file.



@Henry Wong thank you for your participation.

You may feel that this is not the the appropriate location for this question, however the authors of the OCA Java SE 8 Programmer 1 Study Guide advise that this forum be used for this question.

Kind regards
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Melo Mashabane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I issue running the below code, saved a as Zoo.java:



The OCA Java SE 8 Programmer 1 Study Guide instructs to execute the following:

$ javac Zoo.java
$ java Zoo

When I execute:

$ javac Zoo.java

I get the following error message:

'$' is not recognized as an internal or external command, operable program or batch file.

When I remove the $ sign I get the below message.

'javac' is not recognized as an internal or external command, operable program or batch file.

Be really grateful to get advise on the above as I am revising for the OCA programmer 1 exam and would benefit from running code using Notepad and Command Prompt instead of an IDE.

Kind regards.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Since that seems to be a problem related to your other question I shall merge the two discussions.
The error message you quoted is so common that the Java™ Tutorials write about it, and we have an FAQ about it. Those should answer your problem, which is doubtless caused by not setting your PATH correctly.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The dollar sign is part of the prompt from the command line; you should not write your own dollar sign.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
Melo Mashabane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error messages:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:\Users\mashabanem>cd C:\temp

C:\temp>javac packagea/ClassA.java packageb/ClassB.java
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\temp>java packageb.ClassB
Error: Could not find or load main class packageb.ClassB

C:\temp>java -cp ".;C:\temp\someOtherLocation;c:\temp\myJar.jar" myPackage.MyCla
ss
Error: Could not find or load main class myPackage.MyClass

C:\temp>


==================================================

Compiling Code With Packages

Following the Windows Setup

1. Create the two files:

- C:\temp\packagea\ClassA.java
- C:\temp\packageb\Class.B.java

2. Then type this command:

cd C:\temp

3. To compile, type this command:

javac packagea/ClassA.java packageb/ClassB.java

4. To run, type this command:

java packageb.ClassB
 
Melo Mashabane
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved it for anyone else stuck.

- Check your javac path on Windows using Windows Explorer C:\Program Files\Java\jdk1.8.0_91\bin and copy the address.

- On Windows Go to Start - right click on Computer - Select Properties - Select Advanced system settings - Select Environment Variables - Under System variables, scroll and look for 'Path' (without the markers) and Insert the address at the beginning of 'Path' followed by semicolon. i.e C:\Program Files\Java\jdk1.8.0_91\bin; . Do not delete the path existent, just click in and go to the far left end and paste the line above. Do not try anything else, because you just need to link your code to "javac.exe" and you just need to locate it.

- Close your command prompt and reopen it,and write the code for compile and execution.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done sorting your PATH out. Since this is related to your earlier questions, I shall merge the threads.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!