Albany Programming Course Supplement

Command Line Development

Files and Directories (commonly known as Folders)

Computer systems today have hundreds of thousands of files on their disks after they are installed.  People may end up with thousands or more additional files that they have created with various programs or have downloaded.  As people work with their computers, today's application programs and systems create and keep on the disk many more files that most people don't know about.

Problem: Find out how many different files there are in the your computer.  Report three things: (1) how you found it out. (2) How you knew or found out how to find out (It's ok to ask a friend if you don't know.  The important thing is to become able to figure out solutions to all kinds of relevant problems!) (3) An estimate or the exact count.

Problem: Today's systems have various ways of "hiding" files, so most people don't know how to make their computer show them those hidden files.  (1) Explain one benefit for hidden files. (2) Explain one disadvantage for hidden files.

Today's file systems (which are simply the data structures usually on disks that make it practical to work with lots of files) organize the files into folders or directories. Computer system professionals, developers and researchers prefer to use the term "directory" because that term was in use long before computers became commonly available. 

Aside: The word "directory" suggests something that is used to find something else.  The word "folder" was chosen so people who worked in offices with file cabinets filled with paper folders holding documents printed on paper would recognize similar concepts when they first had to deal with computers.   

A very important fact about today's file systems is that a directory can contain both files and other directories.  Computer scientists recognize this situation as a form of recursion.

Problem: Loosely speaking, recursive means a thing is formed out of other things that might include some that are the same kind of thing as itself.  Exactly what are the kinds of things that a computer scientist would name when explaining why a file system is recursive?

Solution: The kind of thing in a file system that might include some things of the same kind is the directory. A directory might, but does not have to, contain other directories.  Besides directories, a directory might contain files. However, it is possible for a directory to not contain any files.  It could be empty or it might just contain directories.  Thus, the kinds of things that a computer scientist would name when explaining why a file system is recursive are files and directories.

That answer is a bit long winded.  Can you explain it more simply?

Solution: A file system consists of objects called files and objects called directories, where a directory can contain zero or more files and zero or more directories.

Computer scientists like to give brief explanations and leave the reader to think about their ramifications.  For example, the simple explanation covers all four of the possibilities for what a directory can contain.

Always use a separate directory

Programming Course Process Requirement: Always put your work for different projects in different directories.

 

Commands to edit, compile and run Java applications

The simplest routine for doing programming in Java is to repeat the sequence of 3 steps:

  1. Create a new file containing Java code or edit an old one.  Make sure the file is saved after you make changes by using the editor. The file's name must be name of the class it defines followed by .java

    Example: Suppose the class is FirstDemoProg, so the file is named FirstDemoProg.java

  2. Compile by giving the command javac FirstDemoProg.java

  3. Run the Java application by giving the command java FirstDemoProg

 

Question: What program called that reads an input file of java source code, and, if it has no syntax errors or missing class definitions, writes a file of Java byte-codes? (1) Java compiler (2) Java Virtual Machine.

Question: What program called that reads a file of java byte-codes that represents a class with a public static void main(String[]) method, and, if all other classes it references can be found, makes to program expressed by the byte codes run? (1) Java compiler (2) Java Virtual Machine.

The CLASSPATH in Java

However, often your programs will use classes besides those you write.  In Guzdial and Ericson's curriculum, these classes include the Picture class.  They are supplied in an archive that expands to a directory named BookClasses.

The java compiler program javac and the Java virtual machine program java must be able to find the source files and/or class files that define all the classes your program uses. However, it is a bad idea to keep copies of say the Guzdial and Ericson's Book Classes in the same directory with any of your projects.

The solution is to communicate to both javac and java the names of the directories where all the classes, your's and those supplied by others, will be found.  To implement this solution you can command the shell to put in the environment the environment variable named CLASSPATH with the value being a colon separated list of the those directory names. 

For example, suppose the directory for all your CSI310 course work is /home/sdc/CSI310. It would be a good idea to put the Book Classes in a subdirectory of that directory for that course's work.  That subdirectory would then be named /home/sdc/CSI310/BookClasses

Then, before starting the project, you would give the shell command:

$ export CLASSPATH=.:/home/sdc/CSI310/BookClasses

To start the project, you would make the shell navigate to your directory for CSI310

$ cd CSI310

Next, make a new directory for the FirstDemoProg project

$ mkdir FirstDemoProg
$ cd FirstDemoProg
What is behind environment variables? 

When you type commands into a connected secure shell client window, everything you type is input to one process that is running a shell program. When your command names an executable program, the shell runs that program in a new process.  The shell process continues to remain in the computer when the new process runs.

The shell process maintains a collection of strings called environment variables and associates to each environment variable another string called its value.  This collection of data is called the environment.

 You can observe all the data in the environment by commanding the shell to print the environment.  The command to print the environment is spelled printenv

Here is how you would give that command:

 $ printenv

The environment (variables and their values together) can used by any program that you command the shell to run. 

The two programs named javac and java have been written by employees of Sun Microsystems (now part of Oracle) to use the value of the environment variable named CLASSPATH for the list of directories to search for .java source files and .class files.


There has been error in communication with booki server. Not sure right now where is the problem.

You should refresh this page.