How do I use the command line?
August 14, 2009 10:16 PM   Subscribe

I am a soon-to-be high school senior interested in Java programming. I bought the Core Java Volume 1 book authored by Sun engineers. I believe I have unzipped, or decompressed, however it's said, the Library Source Code and Documentation using the command line. However, when I look at the folders using the GUI, the folder says it's still zipped. I'm a complete newbie at this who just recently learned about the existence of the command and read a little about how to use it on the internet. Can somebody help me?
posted by bookman117 to Computers & Internet (23 answers total) 5 users marked this as a favorite
 
Are you on Windows, MacOS, or Linux?

What's the command line you used?

simplest thing is probably (if you are on Windows) to get something like WinZip or WinRar or 7Zip. You can right click on the zip archive and choose the equiviement of "uncompress into file FOO", where FOO is the name of the archive.

If you are on MacOS X or Linux what happens if you do a "ls -l" in the directory you have zip and the folder in?
posted by bottlebrushtree at 10:48 PM on August 14, 2009


So unzip it then. Java tend to zip zips in zios in zios, and give them funny extensions liek .jar and .ear.

I also recommend you do the following: download Eclipse, download maven, download Spring roo (or Spring's eclpise clone with roo built in, even better).

Use Roo to make yourself a website. It's literlaly as simple as telling Roo what your domain classes contain. After maven downloads a crapload of jars (and I mean a crapload, go bake a cake or something), you'll have a database-backed webapp runnig on your computer, that you can use by going to localhost:8080.

Go in, and play with it, read your compiler errors closely, step through it in the debugger, which will (all too soon!) get you into the java library source you want to look at, except you'll be able to step through it in the debugger.

Now the debugger is no substitute for studying source, and a roo app will not, out of the box, do everything you want, but it'll let you dive in and hopefully encouter a problem you want to solve that'll motivate lerning.

Before you start coding, download subversion and set up a repository -- this will pay you back a thousand-fold.

And once you have maven, use it to set up a Wicket project; Wicket has a more Swing/application feel that a webapp.
posted by orthogonality at 10:53 PM on August 14, 2009 [2 favorites]


Don't worry about the source so much; just download the JDK and install it. Then download the API documentation (probably requires unzipping) and open it in your browser. Then get on the Sun website and work your way through The Java Tutorial.

You'll need a good editor; Eclipse works well as an integrated dev environment (no commandline stuff required) but it's a bit slow.
posted by polyglot at 11:05 PM on August 14, 2009


And I'll chime in to say I think orthogonality has misinterpreted you "on the Internet"; I would strongly recommend you don't try learning programming or a new language by doing web development as there are a bunch of additional layers there to confuse things. Start with simple text-based things and then think about using Swing if you want some graphics.

Venture into web stuff once you know the language well and also know how HTTP and servlets work.

Likewise, svn is great, but I wouldn't go there at all if you just want to play in a new language. It's hard enough creating a new source file, compiling and executing it without adding a bunch of unnecessary (at this point) complications.
posted by polyglot at 11:12 PM on August 14, 2009 [2 favorites]


Response by poster: Well, bottebushtree, I'm on XP. Um, sorry, but what's Eclipse, maven, Spring, and all that stuff? For coding I downloaded Netbeans, with color-coded syntax and all that, shouldn't that be good enough? Sorry I don't know much about this stuff, but I was told I would probably like programming possibly as a career if my favorite math subject was geometric proofs and trig identities. Plus, I had the experience of using the educational program Karel a few years back when I was a freshman and I found it to be intriguing. Like proofs, it was more a logical deduction process than number-crunching. I really would like to get programming, but all of this preliminary stuff is bogging me down. Anyway, I doubt there's anything wrong with the source code, and maybe I'm not doing anything wrong at all, but I was just afraid that if I continued down the path that the book instructs me to do and forget about this apparent discrepancy that I might screw myself up in some irreversible way. Is that really even possible?
posted by bookman117 at 11:18 PM on August 14, 2009


Best answer: [*points at orthogonality*] hey, you should listen to this dude. Guy knows what he's talking about. and he can probably point you all sorts of ways most people can't. I'm a python-head, so I can't tell you much about java, but I can help with some other stuff.

The first and most important question you have to answer before we can help you is: what OS (operating system) are you running on your computer; Mac OS X, Windows XP or Vista, or Linux? They all have command-line interfaces, and they all have very different methods for doing what you're trying to do.

Since Mac OS X's command line is the most well-hidden and (I think) the least likely to be what you're talking about, I presume that you're working on either a Linux or a Windows command line. If you're in Windows, then bottlebrushtree's recommendation of 7zip is a great one; this awesome open-source program is great for unzipping almost any kind of compressed (or archived) file format, and you needn't use it on a command line if you'd rather not, at least to start out with.

If you're using Linux - and it sounds a bit like you are, at least judging from the way you're talking about it - then first of all good on ya for diving into Linux, which is a great asset to any programmer, and second of all I have a whole other bunch of things you can do that I'll let you know about if that's the case.

As far as what might be going on in particular in this case:

There are two possibilities, as far as I see it.

First off, you probably already know that files are compressed in order to make them smaller to save memory. That's what it means when they're all zipped up. However, often-times you'll find that files seem to have been compressed twice. If you're on Linux, for example, all the time you'll see files with names like folder.tar.gz; and you'll discover that, even when you've decompressed them out of the .gz bit, you still have to decompress them out of the .tar bit. It might seem like they do that just to cram it down even smaller, but when you look, you see that folder.tar is the same size as folder. The actual reason (usually) why they do this is because folders aren't like files; they're specific places in the directory tree, and you can't just go grabbing them and pushing them along. They have to be wrapped up in a container file - and that's all a .tar file (commonly called a 'tarball') is. It wraps up the folder so that it can then be compressed and moved around as though it were actually a file.

Second, the more likely answer to your question is probably this: any good decompression program knows that mistakes often happen when you're unzipping files, and that you don't want to lose the original zipped-up files if that should come to pass. So most good decompression programs will unzip the files in a different place from where the zipped-up files are; a nearby directory, say, or a new folder, or maybe in the /usr or /Documents folder. If you look around, you should be able to find the files that you extracted from the zipped-up ones, which probably were not deleted or even changed in any way.
posted by koeselitz at 11:26 PM on August 14, 2009 [1 favorite]


It is possible to screw yourself up in some irreversible way but you've avoided the most traditional way to do that already. (Sorry, programming joke.)

Anyway.

You can always just delete the whole mess and start over if you screw up. I'm wondering if maybe you unzipped it in such a way that the zip file's contents ended up somewhere you didn't expect (it doesn't normally replace the .zip file, it leaves it there and creates a directory containing whatever was inside it). Or, as orthogonality said, it might just be a zip file which contains more zip files.

I know this doesn't really answer your question, but if Java's being a PITA, you might also try learning Python. (One can spend forever debating the relative merits of different languages, though, so if you've started down the road of learning Java maybe it's better to just continue with that for now.)
posted by hattifattener at 11:40 PM on August 14, 2009


bookman117: Well, bottebushtree, I'm on XP. Um, sorry, but what's Eclipse, maven, Spring, and all that stuff? For coding I downloaded Netbeans, with color-coded syntax and all that, shouldn't that be good enough? Sorry I don't know much about this stuff, but I was told I would probably like programming possibly as a career if my favorite math subject was geometric proofs and trig identities. Plus, I had the experience of using the educational program Karel a few years back when I was a freshman and I found it to be intriguing. Like proofs, it was more a logical deduction process than number-crunching. I really would like to get programming, but all of this preliminary stuff is bogging me down. Anyway, I doubt there's anything wrong with the source code, and maybe I'm not doing anything wrong at all, but I was just afraid that if I continued down the path that the book instructs me to do and forget about this apparent discrepancy that I might screw myself up in some irreversible way. Is that really even possible?

Ah ha - I was waiting to see how open you were to change.

Here is my big recommendation: learn Python instead. I say this for several reasons.

The standard 'gospel' credo of Python is hidden within the language itself; when you type 'import this' into the command interpreter, you get

THE ZEN OF PYTHON
by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!


First of all, Python is simple. Java is a huge, powerful language that offers literally millions of extensions and thousands of different ways of doing many tasks. Python, on the other hand, strives to have only one way to do anything anyone would want to do so that the language remains focused and so that code remains reasonable and easy for everyone to read.

Second of all, Python is in my mind a more inherently mathematical language. It makes mathematical sense on a fundamental level where lots of other languages don't; indexes are in the right place all the time, for example (C++? Not so much) so that it's a lot easier to get used to thinking in terms of the language and approaching it that way. I believe that this is because the designer and creator of Python, a Dutch guy named Guido Van Rossum, was actually by training himself a mathematician.

Finally, Python is intentionally beautiful. Lots of people might disagree, but I think it's incredibly elegant; it often comes out looking very much like English prose, and yet for all that simplicity it's extraordinarily powerful.

hattifattener is right - if you're dead-set on Java, stick with it, as they're roughtly equivalent object-oriented languages that both have good support and active development. I only push Python because, since I started learning programming a year ago, it's consistently been comfortable and challenging at the same time. It has so few of the many 'things that don't make sense' that so many languages seem to have, and it's such an intuitive way to start learning that it's never been less than awesome to me.
posted by koeselitz at 11:53 PM on August 14, 2009


koeselitz has a point. (As does polyglot.)

java is not a good first language. (In fact, it's not a good last language. I do it professionally because it pays me six figures -- if I had my druthers, I'd code in C++, or just do database design.) It's needlessly tedious and verbose, and it's explicitly designed to allow hiring mediocre programmers by preventing them from screwing up, and not to let good programmers do their thing.

And the Collections classes are travesties, and their dependency on Object.hashCode() causes all ends of problems. (I won't bother explaining why here.)

Get a copy of Dive Into Python. Nice language, though I dislike weakly typed languages. (There's a story here, which I omit.) If you really want to be hard-core, learn C++ after the python -- knowing C++ basically gives you java. But learning C++ takes basically six months of obsessive monk-like concentration.
posted by orthogonality at 12:37 AM on August 15, 2009 [1 favorite]


Here's a completely different tack, for the novice programmer wannabe:

For the moment, screw Java, Python, C++, C, C#, .NET, and all the other programming language alternatives that may occur to you, for the next 3 months. Learn, first, to store, retrieve, and manipulate data in various database systems, as a precursor to learning programming, per se. Once you've groked flat file databases, b-tree based data stores, and understood the basics of Relational Database Management Systems (RDBMS), you'll have high level tools like Structured Query Language (SQL) at your command, when you need to manipulate data. Moreover, you'll find that off-loading the indexing and management of data (and underlying physical file structures) to an appropriate database system pays big dividends in your programming efforts, in terms of reliability, scalability, and performance.

Big payoff: embedded SQL is supported, one way or another, in almost every programming language you'll ever come across. So, every time you face a problem, which is, at root, dealing with structured data, you'll have a consistent means of dealing with it, via embedded SQL and a SQL compliant DBMS of appropriate structure, in whatever language(s) you choose for programming.

The benefits of this approach are:
  • You think, from the outset, of computer systems, as systems, which do a lot of low level work for you, as a programmer, freeing you to think at a higher level
  • You learn to separate the issues of data, and data structures, from programming issues, up front
  • You'll find that knowing how to work with database management systems gives you a common language with other programmers and IT personnel whose responsiblities are the organization and storage of data, that your mainline programs may call.
You can download many free database management systems, and begin working with them immediately.
posted by paulsc at 2:01 AM on August 15, 2009 [1 favorite]


bookman: all these unknown terms can be googled. Most of them you will find important later on but for now, not so much. Eclipse is basically NetBeans so you're OK there.

My god, people. Let's just leave out all the language zealotry (it's not like the world doesn't have enough, eh) or the suggestions to do more complex things like play with databases.

My advice (as a comp sci PhD who taught programming to undergrads and professionals) is to start simple and learn the absolute fundamentals of imperative programming: functions, selection (if/else) and iteration (for/while). Ignore all the OO stuff initially until you're comfortable with that; same goes for exceptions, databases, web and all that jazz.

It is true that Java is not a great first language and the main reason is that it has a bunch of stuff you don't initially need... but then that's true for any language that's used for real. You can choose to learn on a toy language that will get the concepts across more easily or you can learn on a more full-featured language with features you don't need yet and that may pollute your way of thinking. Best option is not to ever become married to one language but retain the mental flexibility of thinking in a few. Where to start doesn't really matter but you do have masses of learning ahead of you.

If you go with python, you'll need to learn some command line stuff to run the compiler or interpreter but that's a good thing anyway. Google for "xp cmd tutorial" or similar and I'm sure you'll find something.

While interpreted languages are easy to write quickly, I would recommend you start with a statically typed language (google that), which means that it will detect a larger group of errors at compile time instead of failing mysteriously at runtime. Ada is the prototypical example there (very formal, static and kind of easy to learn) but it's hard to get started with as a beginner. Python is a lot more dynamic than I would recommend for someone just starting out... but if you're smart you'll be fine eventually with whatever you start with.
posted by polyglot at 4:04 AM on August 15, 2009 [2 favorites]


I am learning Python, I am also learning Java, but have done Java for longer.

So, Senior in the USA. what colleges are you interested in? Do they have a language they teach CompSci majors as standard? Play around with that language.

Language learning is good, but the knock down best thing to learn is HOW TO PROGRAM. whatever, in whatever language. Functions, like in Math. How to loop. How to tell the computer to do math, etc. Once you learn this you can learn any other language easily. (Of course you need some kind of programming language so you can see what you are doing.)

Have you looked into doing AP exams? What about the Computer Science A? (If so, learn java. it's what is on the test.) If not:

It doesn't matter what language you pick (much) just pick one. Don't listen to the naysayers once you have chosen. This site has lots of examples of a simple program: one that outputs "Hello World" in many languages.

Oh, and play with the command line, learn how your computer works. It's also very helpful if you pursue a degree in Computer Science.

keep playing with maths. keep playing with proofs. Keep exploring what path(s) you want to take.

Oh, and learn how to be a Google ninja. Seriously useful.
posted by titanium_geek at 6:13 AM on August 15, 2009


Here is a handy list of commands for WinXP.

Try using the dir command to see if the individual contents of the compressed file are now listed in the directory you decompressed them to. If they are not, then clearly the process you went through to decompress them didn't work.

Since you didn't specify what you did in the first place, it's going to be hard to provide any more specific help than this. If you'd like us to give further advice, could you please tell us how the directory was compressed (i.e., what file extension did it have? .zip, .tar, etc), and what you did to decompress it?
posted by voltairemodern at 6:59 AM on August 15, 2009


The command line on Windows is a last resort. This is because Microsoft hates the command line and has not updated its terminal program in 548 years.

Use graphical tools. To unzip a file, right-click on it and choose "Extract here...", or whatever the option is. If that doesn't work, download WinZip.

Now, if you like the idea of a command line, you might secretly be a Linux person. There is no shame in this. You can install Linux in a lightweight, no-commitment way using the Wubi installer.

I am now going to bite my tongue and not get involved in the Java/Python holy war.
posted by qxntpqbbbqxl at 7:43 AM on August 15, 2009 [1 favorite]


I believe I have unzipped, or decompressed, however it's said, the Library Source Code and Documentation using the command line.

What exactly did you type? What was the output?

Can somebody help me?

Help you what? Unzip something? I don't use Windows, so I don't know how it's done over there, but unzipping doesn't sound like something you'd need to use the command line for to me.

Also, most programmers enjoy tinkering with their computer, and know the command line, svn, IDEs, troubleshooting their OS, and various assorted fluff that's not programming. However, one of my good friends is a fantastic programmer, but not particularly great with computers. He's a cognitive science PhD and does a lot of Matlab programming. So don't fret if you just don't like all this other non-programming part of the process, although it is helpful to enjoy it.
posted by losvedir at 9:56 AM on August 15, 2009


Best answer: I donno what you've unzipped; it's probably whatever source came with the CD. Do yourself a favor, and go to a couple of local libraries, and look for java programming books. One or two of them is bound to discuss installing Java from the internet, as God intended. Integrated Development Environments (IDEs) like NetBeans can be a mixed blessing. They optimize the workflow for experienced programmers, but can be intimidating to novice programmers. On the other hand, the windows command line generally sucks.

But there's something to be said for Python. It's simple to get started with, and comes installed on OSX and Ubuntu (and most other Linuxes).

You mentioned you like math and proofs. Project Euler is a set of math problems intended to be solved by computer. Once you've gotten familiar with a language, it's not a bad idea to start there. Programming proofs are a bit harder to come by via the Internet -- they're mainly academic and involve things like First Order Logic and so on. Prolog is a language designed for proofs and logic; I've not used it myself but I understand it's probably the most widely known (and hated) systems.

Proofs are awesome, and can be applied to programs themselves. This might seem like a useful skill, but I've yet to encounter anyone in industry who does it. But there's a certain amount of satisfaction from creating a crazy algorithm and proving it returns the same thing as a slower, obvious one.
posted by pwnguin at 11:53 AM on August 15, 2009


Best answer:
Proofs are awesome, and can be applied to programs themselves. This might seem like a useful skill, but I've yet to encounter anyone in industry who does it.
Which reminds me of something I wanted to add: if you enjoy proofs and identities, you may be more interested in computer science as a career than run-of-the-mill programming. (Or, for that matter, math itself. Or any of a zillion other things, come to think of it…)
posted by hattifattener at 12:02 PM on August 15, 2009


I know that my big soap-box Python speech up there might seem daunting; really, just choose a language and stick with it, and you'll go far. At the age you're starting at, you'll certainly end up learning other languages anyhow; and the path you take to get there can be very useful no matter what it is.

One last thing: stay versatile, and have an idea of what other programming languages are like even if you don't really know them. And one of the best things I did for myself early on was page through the first few chapters of the greatest computer programming book ever written: The C Programming Language, by Dennis Ritchie and Brian Kernighan. This old tome is the classic book on how to learn to write computer programs. For example, you'll soon notice that everybody always starts with an example program that simply prints the phrase hello world! Well, that came from The C Programming Language - and it was an ingenious way to start off learning the language with something very simple and yet at the same time practical, so that you're already doing something with it even before you've really even begun to learn it. If you look over the first chapter or two, you'll get a lot of things that are common to all programming languages - variables, types, conditionals, statements, functions, et cetera - and, while a lot of it will be C-specific, the book gives a better idea of how computer languages work than almost any other. You don't really need to study it, but The C Programming Language is a handy thing to have glanced through. If you want a copy, I can email you the pdf.
posted by koeselitz at 2:49 PM on August 15, 2009


Response by poster: Well, pwnguin, and everybody else out there, I downloaded everything from the internet. I did this with much help from this guy I happened to run into in Barnes & Noble, the guy who suggested I would like programming if I liked geometric proofs and trig identities, and also suggested Java as my first programming language. He was there to figure out the rules of the Chinese board game Go and then to make a program that could beat a human someday. For all of you who know how to play that game, it's a lot more difficult for a computer than chess since you can't use the "brute force" method of thinking about every possibility and so forth that Deep Blue used to beat Kasparov. Anyway, that was his background. Quite a serendipitous meeting; I just happened to know the rules of Go and helped explain it to him and then we just sorta went on from there. Anyway, biographical anecdotes aside, that guy no longer answers his phone for some reason, and it was through the efforts of him and myself over the phone together that allowed me to download the JDK and add the jdk/bin to the execution path so the OS (XP) could locate the necessary executable files. So then I executed the command jar xvf .../src.zip on the command line after typing in mkdir src and then cd src, just as the book told me to. Then a bunch of stuff (I know how stupid that sounds) kept appearing in the command line screen until eventually it said that it had completed the task. Anyway, I'm sure it's probably fine, and yeah, I might look into another programming language, especially since where I go to school there are a few teachers and several students who are math and computer geniuses and could probably help me out with this endeavor. I'll be taking an elective called video game programming in the spring, which I assume uses Visual Basic. I think I'll probably just plug ahead and hope nothing weird happens later. I'm probably just being paranoid
posted by bookman117 at 5:53 PM on August 15, 2009


Proofs are awesome, and can be applied to programs themselves.

Not to mention programs are proofs :)
posted by qxntpqbbbqxl at 10:00 PM on August 15, 2009


Then a bunch of stuff (I know how stupid that sounds) kept appearing in the command line screen until eventually it said that it had completed the task. Anyway, I'm sure it's probably fine

Yep. most likely fine. :) See, this is how the command line works- you talk to the computer, it talks back, and you work out useful information.

Alright- now you need to start with a hello world program. http://java.sun.com/docs/books/tutorial/getStarted/index.html is a good place to start.

The code goes in a text file (named something like HelloWorld.java) and you run javac HelloWorld.java from the command line, and this makes a file of 'bytecode' called HelloWorld.class. you then tell java to run your program: java HelloWorld and there you go.

The textbook that I bought and found useful was Big Java. (Also less useful Sams Teach yourself Java in 21 days)

ditto the above to consider Computer Science if you like Mathematical proofs.

VB is easy, but some would say it's an ugly way to program.. but don't listen to naysayers (much) of course!
posted by titanium_geek at 11:28 PM on August 15, 2009


Best answer: bookman117: I think I'll probably just plug ahead and hope nothing weird happens later.

Sounds like you've already got the essential part of programming down. Heh.
posted by koeselitz at 9:14 PM on August 16, 2009 [1 favorite]


Man, there is some pretty insane advice in this thread. The guy wants to write a "hello world" app in java and people are telling him to setup a web server and write webapps, learn python, and spend a month working with databases and SQL. Crazyness.

Anyway, if you're still reading this stackoverflow is a great resource for asking programming questions these days.
posted by delmoi at 7:41 PM on January 5, 2010


« Older Request letter help.   |   Half-remembered 1950s coming-of-age film Newer »
This thread is closed to new comments.