File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes java programs in vi editor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java programs in vi editor" Watch "java programs in vi editor" New topic
Author

java programs in vi editor

rameez hussain
Greenhorn

Joined: Sep 15, 2010
Posts: 10
i just wanted to know if there is a different way to type java programs in the vi editor? cause i am getting a lot of errors saying 'illegal character'.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Eh I don't understand your question. There will probably be another way but maybe we can spot the problem if you tell us what you're doing. And just some some code that causes those errors. In conclusion TellTheDetails.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Compilation errors? Vi errors?
rameez hussain
Greenhorn

Joined: Sep 15, 2010
Posts: 10
well i typed the following code:

package example.hello;

import java.rmi.Remote;
import java.rmi.RemoteException;

public interface Hello extends Remote {
String sayHello() throws RemoteException;
}

i named it Hello.java and then typed Server.java and Client.java too

The programs worked fine in my laptop but theyre giving me errors now when i tried to run them on another server.

Im getting around 35 errors, all in Hello.java and all of them say "illegal character" with some characters which look like garbage. Im not sure if this is vi errors or compiler erros.

I ran javac -d directory Hello.java Server.java Client.java. that is when i got these errors.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'd make sure you're saving the file in a sane encoding first, and that it makes sense on the other system as well.
rameez hussain
Greenhorn

Joined: Sep 15, 2010
Posts: 10
i dont understand. could you please be more elaborate? i dont know what you mean by encoding. you see im new to java programming. ive just started.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

Are you seeing a lot of ^M sequences at the end of each line? If so, that means you have the dreaded Windows-line-breaks-on-a-Unix-system problem.

Unix uses \n as line breaks. Windows uses \r\n. Notepad can't handle \n -- it will display it as little blocks. Similarly, VI can't handle \r\n -- it will display the \r as ^M.

You should ensure that dos2unix (and it's brother in arms unix2dos) is installed, then run that before editing. The first will replace all \r\n sequences with \n, the other will do the inverse.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
rameez hussain
Greenhorn

Joined: Sep 15, 2010
Posts: 10
Hmm. I see. But im using Ubuntu. And there is Linux installed on the other server. Its actually my university server, so i cant really install anything there. Im guessing everything thats needed is already installed. And im pretty sure there are no errors in the java programs im using.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

You can download the two EXE files for your Windows box here: http://www.bastet.com/

Then use dos2unix.exe before you send the file(s) to your Unix box.


Regards, Rene Larsen
Dropbox Invite
 
jQuery in Action, 2nd edition
 
subject: java programs in vi editor