Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java programs in vi editor

 
rameez hussain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compilation errors? Vi errors?
 
rameez hussain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
rameez hussain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic