aspose file tools*
The moose likes Java in General and the fly likes Programming from the command line? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Programming from the command line?" Watch "Programming from the command line?" New topic
Author

Programming from the command line?

Tim Hoyle
Greenhorn

Joined: Aug 28, 2010
Posts: 2
Guten Tag everyone,

I was wondering if there was any way to program from the command line prompt. I am running windows 7, and I can compile and run code using the javac and java commands with the JDK, but I was wondering if I could program from the command line as well, instead of using an IDE or even NoteBook. Thanks in advance.
-Tim Hoyle
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

Hi Tim,

and welcome to JavaRanch

What exactly do you mean by "programming from the command line"? As Java isn't a scripting language and therefore doesn't provide something like a scripting shell you should at least have some kind of editor. Maybe the old command line editor (don't know if it's still included in Windows 7) is enough for you then you can program from the command line. More or less. It may work but it's surely not very convenient without any tool support.

Marco
Tim Hoyle
Greenhorn

Joined: Aug 28, 2010
Posts: 2
Marco,

Thanks for the reply.

I know what you mean about tool support. It is a lot easier to write code with an editor. However, I have a buddy who is asking me to research the idea for him. I have always used netbeans to compile and run programs, personally.
I am simply researching the idea of writing code from the command prompt (yes, windows 7 still has it) and saving it in a .java file so that one can compile it with the javac command and run the .class file with the java command.

-Tim Hoyle
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

@Tim,Welcome To JavaRanch
Yes You can do that.But provided you provide the argument while running the code


SCJP6.0,My blog Ranchers from Delhi
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

A more convenient approach would be to find a command line editor of your choice which can help you to automate at least the edit-compile-run-cycle a little bit to speed up development. On Linux for example Emacs or vi are well-known editors which at first seem to be simple command line editors but there are many ways to extend the core functionality which makes a little command line IDE of these editors. I guess they are ported to windows too (maybe via Cygwin) or probably there are other command line editors for Windows which allow similar features.

Marco
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11279
    
  59

I agree with Marco - using some sort of editor (even the "edit" command (assuming it still exists in Windows 7)) would be better than straight command line. However it is possible:

Verify that it was stored correctly:

Compile and run it:


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

OK, this is hardcore But in this case you should at least eliminate line breaks altogether and reduce the source file creation with "echo" to a single echo command
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11279
    
  59

Andrew Monkhouse wrote:... even the "edit" command (assuming it still exists in Windows 7)) ...

In case you are unaware of that editor, it was introduced around DOS 4.0 (I think - I remember using it prior to Windows 3.1). From the command line, you enter "edit [filename]" (e.g. "edit Hello.java") and it opens the file in a simple editor:



Not a great editor, but it will get the job done. And is way better than millions of "echo" type statements.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11279
    
  59

Marco Ehrentreich wrote:OK, this is hardcore But in this case you should at least eliminate line breaks altogether and reduce the source file creation with "echo" to a single echo command

And reduce all class names and variable names to a single letter!
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

And reduce all class names and variable names to a single letter!

Absolutely! Just imagine all those wasted bytes!

Btw. your screenshot reminds of the times when we really used this editor to save a few bytes just by tweaking our AUTOEXEC.BAT or CONFIG.SYS file! Those were the days...
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11279
    
  59

Marco Ehrentreich wrote:Btw. your screenshot reminds of the times when we really used this editor to save a few bytes just by tweaking our AUTOEXEC.BAT or CONFIG.SYS file! Those were the days...

Yep - I remember those days!

And writing batch scripts that would create separate batch scripts based on user inputs that would then be run to perform installations or upgrades of software.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11279
    
  59

Oooh - just thought of going even more hardcore!

Get Vim for PCs, and combine it with eclim to give you a command line Eclipse.
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

Back then it was at least possible to know all the files on your harddisk and to understand what this machine was doing... most of the time

@Tim: It's not necessary to work without an IDE just because of these memories
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

copy con > ClassName.java

Then just ^Z to close the file.

Why... different issue.

I remember when my friend Tom got his Apple ][+ but we had no RF converter so we wrote BASIC/assembly that made sound without being able to see *anything*.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Programming from the command line?
 
Similar Threads
runtime exec
Array Conversions on Dan's Topic Exam
Importance of java/javac for SCJP Exam?
gui side commandline parameters
assertions...