How to save and run Java file in PuTTY?

I'm a complete newbie to AWS (Amazon Web Services) so this might be a basic question.

I have created an EC2 instance on AWS. I have a Windows machine, so I am using PUTTY to connect to my Linux instance.

After connecting to my EC2 instance, I used the following command to write Java code,

vi java First.java

      

After writing the above code, I got the screen below and I wrote Java code for a simple "Hello World",

enter image description here

The problem now is that I am stuck here, what should I do to save what I wrote? Where will it be stored, on my laptop or EC2? Is there a way through which I can just download the file and then just run it from the terminal?

Thanks in advance.

+1


source to share


2 answers


I have been using putty since almost two years.

U should open vi editor using "vi filename.java"

Enter the program and then tell "Esc: wq" to ignore spaces. And Esc is the Esc key on your keyboard.



Then compile your program using "javac filename.java"

N then run with java filename.java

+2


source


See Saumil ..

When you log in, the directory you landed in is your users home directory .. Just like in your case "ec2-user" ..

So, if you do "vi filename" without changing the directory, then a file is created in the users home directory "/ home / ec2-user" .. N, which is represented by the ~ .. symbol which represents the current users home directory ..



N, then if you log out and log back in, the file stays there. Nothing happens with this file if you manually delete it.

With the above snapshot, I can see that after logging in, you change your user to root .. But if you could see after running sudo, you still remain in the same directory. N "~" changes to "ec2-user" because the home directory of the root users is different.

+2


source







All Articles