Visit Our UNIX and Linux User Community

Using basic UNIX commands to make/compile JAVA files

Thread Tools Search this Thread
Top Forums Programming Using basic UNIX commands to make/compile JAVA files
# 1  
Old 04-29-2014
Using basic UNIX commands to make/compile JAVA files

This is my first post, and I just learned what UNIX was this week. For a JAVA programming class I am taking, I must be able to create a directory in UNIX, use the nano command to create a JAVA program, compile it, and then run it on the command prompt using the java command.

For some reason I am having trouble, here is what I have tried.

mkdir project13
(I have now created a directory named project13)

cd project13
(I have now changed from default directory to project13 directory)

nano HelloWorld
(This should create a file named HelloWorld that I can edit.)

Here is what I have typed in the nano editor for HelloWorld
         public class HelloWorld {
                  public static void main(String [] args) {
                            System.out.println("Hello World!");

I then hit ctrl+x to exit and select NO, I'm not sure what modify buffer means...

then that takes me back to the command prompt.

I then enter javac to compile the file but it gives me an error:
cannot find or load main java class

what does this mean?
and what Have I done wrong to this point?

Thanks in advance UNIX/Java world! Smilie

Last edited by Franklin52; 04-30-2014 at 03:28 AM.. Reason: Please use code tags
# 2  
Old 04-30-2014
Check out the info here: "Hello World!" for Solaris OS and Linux (The Java™ Tutorials > Getting Started > The "Hello World!" Application)

If you have successfully saved your source code and compiled your source you should see two files when you do the ls command in your directory from the command line.

If you still have a problem post the results of ls command here.
# 3  
Old 04-30-2014
I understand the logic of creating a file through the text editor, compiling it, then running it through the command prompt. I am still having problems

when I do the ls command, I can see any listed file.
I even type nano filename in order to see the text of filename in the text editor and it is there

however, when I use these commands

java filename

The file can not be found, or I get a message saying that the main java class cannot be loaded

My steps:
create a directory: mkdir directoryname
change to directory: cd directoryname
create a file: nano filename
Ctrl+x, NO
compile the file: javac file cannot be found
java filename: cannot find or load main java class
# 4  
Old 04-30-2014
It helps to read what the computer is telling you. When you hit ctrl-x, nano asks you if you want to save first, and warns you "ANSWERING "No" WILL DESTROY CHANGES". You tell it "no".

Last edited by Corona688; 04-30-2014 at 02:24 PM..
# 5  
Old 04-30-2014
I also noticed that you created your source file with no extension.

I guess all java source files must end with the extension .java
This User Gave Thanks to Yoda For This Post:
# 6  
Old 05-01-2014
I've saved the file with ctrl+X then YES option, but that still didn't work I got the same error.

Yoda, your answer was correct. I recreated the source file with the .java extension and it worked for me.

Thank you Yoda! Wise, you are. Practice more, I must.

Previous Thread | Next Thread
Test Your Knowledge in Computers #243
Difficulty: Easy
The starting point for host-to-host communication on the ARPANET in 1969 was the 1822 protocol.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with writing a script to run java commands in sequence in UNIX

Hi, Brand new to these forums, and I hope that someone can help me out. I'm trying to run the following command in UNIX java -jar GenomeAnalysisTK.jar -T SplitSamFile -dt NONE -R reference.fa -I my.bam --outputRoot /my/path/SampleFiles/Sample_ It executes the SplitSamFile from GATK, but I... (3 Replies)
Discussion started by: Wixaros
3 Replies

2. UNIX for Dummies Questions & Answers

How to compile and run java in UNIX?

Hi Im using MobaXterm Unix on my windows XP.I want to compile java in unix.I have installed java to the following path C:\Program Files\Java\jdk1.7.0_09\bin In order to compile the java prog im typing the following command after entering into the bin directory: C:\Program... (2 Replies)
Discussion started by: ak3141
2 Replies

3. UNIX for Dummies Questions & Answers

Compiling gcc to compile make to compile yaboot

I have just installed OpenBSD on a 333MHz PPC iMac G3. It has a 6GB HDD that has been partitioned as 1GB MacOS 8.5.1, 3GB MacOS X 10.3.9, 2GB OpenBSD 4.8. I now need to install a bootloader so that my computer can recognize the OpenBSD partition at startup. I have been trying to install... (0 Replies)
Discussion started by: t04st3r
0 Replies

4. HP-UX

Make command performs badly and refuses to compile on 200000 files

I am trying to run make command on 200000 files in HP UX but it refuses to compile giving a message that " command line is too long .stop" I checked and found out that there is a limit imposed by the operating system on the command line .for Eg refer following link : The maximum length of... (6 Replies)
Discussion started by: madhur.tripathi
6 Replies

5. Programming

Run Unix commands from Java

Greeings all Im trying to excute a command from Java and direct the output to the main output screen or to another file .... can you please help with this ? can I use filewriter for this ? Here is my code.... import; import; import;... (3 Replies)
Discussion started by: yahyaaa
3 Replies

6. UNIX for Advanced & Expert Users

How to execute multiple unix commands in one session from java

Hi, Iam trying to code in java and wanted to run the commands in the Unix remote servers. I have the following code to run multiple GREP commands in a single session. But when i execute this, the first command executes successfully, whereas from the next line it says "Exception Occured... (1 Reply)
Discussion started by: gravi2020
1 Replies

7. Programming

compile java with GUI on unix system/putty

is it possible in the first place? if so, how should I go about it? (0 Replies)
Discussion started by: finalight
0 Replies

8. UNIX for Dummies Questions & Answers

Why do basic unix commands not work in BASH

Why do basic unix commands such as "ls" not work in "BASH" mode?? I am frustrated!! (10 Replies)
Discussion started by: PixelLover
10 Replies

9. Windows & DOS: Issues & Discussions

Basic Unix Commands for cygwin

Hi. I'm New user for this Forum.Presently i'm working with Cygwin I want to know the basic commands that will be used for Cygwin. Can anyone guide me on this regards Thanks & Regards Sanjay (0 Replies)
Discussion started by: sanjay.karthik
0 Replies

10. UNIX for Dummies Questions & Answers

Unix basic commands

I need a sheet with the basic unix commands , and commands for VI editor. Does anyone know where i can get them. (3 Replies)
Discussion started by: Peter Spellman
3 Replies

Featured Tech Videos