tags:

views:

135

answers:

2

I am currently writting programs in linux like this: From the command line I do following steps:

$ touch project.java
$ nano project.java

and I write the code.

I have questions: how can I create new classes, interfaces and so on? Because in IDE like Betbeans I can right click on projects name with and choose "create new class" or "create new interface" and it is created but how do it in Linux if I dont use an IDE?

+4  A: 

If you don't use an IDE, you type everything up yourself, with a command line editor - emacs, vi, or nano, like you were using before. (or CAT >> for serious pros).

An Interface looks like this : ( Read Java Sun's tutorial for more about Interfaces! )

interface Bicycle {

       void changeCadence(int newValue);   // wheel revolutions per minute

}

A Class looks like this (Read Java Sun's tutorial for more about Classes!) :

class Bicycle {   
       int cadence = 0;    
       void changeCadence(int newValue) {
            cadence = newValue;
       }
}

Etc, it's all in the documentation. Keep reading Java's handy tutorial and you'll find it all.

rlb.usa
I noticed Sun's tutorial sends the user into NetBeans. I managed to find this tutorial: www.javacoffeebreak.com/java101/java101.html based on command line and editor, and this one: ant.apache.org/manual/tutorial-HelloWorldWithAnt.html using ant. Similar stuff may be found by googling for `java "hello world" javac`, where "javac" is a good hint that you're looking to run the compiler directly.
Carl Smotricz
I am thinking about downvoting you. Not because you gave a wrong answer, but a bad one. IMHO, you should have said "learn Java". If someone asks this question, this means he does not really understand java and needs to learn.
elcuco
@rib.usa - not _everyone_ is a native English speaker. Your answer borders on insulting the OP. If you find a question incomprehensible or too 'n00b', you can exercise your vote as well as your decision to _not_ answer the question. I'm not down-voting you, because your answer is technically correct. However, I am compelled to say, that was harsh and rather uncalled for.
Tim Post
@Tim Post At time of question posting, the question and code were a jumbled mess (check the revisions). I don't have edit-question moderation abilities. I meant to be helpful by providing a more comprehensible translation for native English speakers ; one was provided before I finished typing my answer. There is no difference between my posting a translation and a highrepuser rewording the OP's question except that I pointed it out. I'm sorry that you found my wording offensive, I'll remove it.
rlb.usa
@elcuco I think reading/studying Java's documentation/tutorials are a great way to learn Java. ; )
rlb.usa
+2  A: 

The current approach works, if you want to avoid IDEs (except the touch is unnecessary).

Just type the entire source code yourself.

For example to create a class called Foo, use your preferred editor and edit a file Foo.java with the following content:

public class Foo {
}

Save and compile and you're done.

Joachim Sauer
how call in in main project?
`Foo myFoo = new Foo(); myFoo.bar();`
rlb.usa
@davit-datuashvili: You're asking us to teach you all the basics of Java. You'd be better off reading [a tutorial](http://www.javacoffeebreak.com/java101/java101.html).
Carl Smotricz
@davit: what is a "main project"? Maybe you should indeed use an IDE. They **do** run on Linux as well ... Otherwise: http://java.sun.com/docs/books/tutorial/getStarted/index.html
Joachim Sauer
@Joachim Sauer: I was going to recommend "the" Tutorial as well, but I noticed they're now basing it on using NetBeans. There are, however, tutorials available based on editors and command line.
Carl Smotricz