Results 1 to 10 of 10
  1. #1
    gcampton Guest

    Default Organisational EXPERTS!

    Hello, I'm wondering how people organize their code on there computers and backups. Because at the moment I have c++, java folders. with subfolders weeks 1-20 and then subfolder examples, etc and in the case of c++ is split into scripting/coding examples. Also every bit of tinkering I have done, is typically lying around in random places, Some in Documents, some in Cygwin/home/* some on desktop, some in public folders... eclispe/workspace, eclispeC++/workspace, cb/workspace, netbeans/workspace

    While I don't need to look at this code often I still need a better system than the one I have and I would also like to setup a sync with a portable drive I have. So does anyone have suggestions as to how to organize code rather than in the format that I learned it.(weekly notes)??

    this is from last semester and about to head into a new semester, so I'm about to be bombarded with even more.

    Oh and YAY for me I got Distinction in java (A) Credit in C++ (B) and credit in database...

  2. #2
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    6

    Default

    For me, I keep ALL my code in Eclipse. I have many different projects and have several "working sets".

    Edit: When I use Netbeans, I import the Eclipse project, but keep the files in the Eclipse project folder (I don't create a separate Netbeans folder). This way, I can use my code in both Eclipse and Netbeans, but have all the code stored in one location.


    I'm going to give examples of how I would organize Java code that is split between several courses and several projects for each course.


    First, I would create a separate project for each assignment. This way, regardless how many assignments there are, they can be easily viewed and accessed. Also, remember to add any "resources" (i.e. files) that may accompany the project.

    I put my all my resources in a "res" source folder, using subfolders, as necessary. Then, I access them using the following code

    Java Code:
    <ClassName>.class.getResourceAsStream(<FileName>)

    For example, for a Class named "ReadResource" and a file named "input.txt" in the "res" source folder, you use the following code to retrieve the InputStream to the resource.

    Java Code:
    InputStream inputTxt = ReadResource.class.getResourceAsStream("input.txt");
    Notice that "res" isn't part of the filename, since all source folders are merged together, and reside in the "code's root folder". For example, if you were to extract the project to a jar, you would see input.txt in the jar's root directory (and not in a "res" subfolder).


    Second, create a working set for each course. If there are many projects in the course, create multiple working sets, one for each of the course's different units. The working sets will allow you to see just the projects that are relevant to the current project (without cluttering your workspace).

    Third, when working on a project, select the working set for the project to view only the projects in that working set.


    I find that this form of organization makes it easy to find what I want, and to backup my code.


    As for backup, I use Mozy. A free account gives you 2 GB of space, and it is very easy to backup all your project files (and any other files you want).

    I have it setup to backup not only my Java code, but my entire Java workspace (which includes the config settings and the code), as well as all the config files and data on my flash drive. I don't backup EVERYTHING on my flash drive (e.g. program EXEs), but I backup all the settings for each of my programs on my flash drive. That way, if my data is loss, I only have to download several programs, but my settings are intact.

    Mozy performs automatic backups (I have mine set for once a day), and automatically keeps a backup of every change. So, if the file is changed everyday, you have each day's backup. If the file doesn't change, it doesn't backup the file (saving you space).

    With mozy is also very easy to restore, since it adds "MozyHome Remote Backup" to Windows Explorer, creating a very easy navigation of your files, allowing you to then restore a file to its original location, or a separate location of your choosing.


    Edit:
    If you opt to get Mozy, please use the following link (which includes my referral code), Mozy. By including my referral code, each of us will get an additional 512 MB of free space!
    Last edited by CodesAway; 01-05-2010 at 02:44 AM.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  3. #3
    gcampton Guest

    Default

    Quote Originally Posted by CodesAway View Post
    I put my all my resources in a "res" source folder, using subfolders, as necessary. Then, I access them using the following code

    Java Code:
    <ClassName>.class.getResourceAsStream(<FileName>)
    For example, for a Class named "ReadResource" and a file named "input.txt" in the "res" source folder, you use the following code to retrieve the InputStream to the resource.

    Java Code:
    InputStream inputTxt = ReadResource.class.getResourceAsStream("input.txt");
    Notice that "res" isn't part of the filename, since all source folders are merged together, and reside in the "code's root folder". For example, if you were to extract the project to a jar, you would see input.txt in the jar's root directory (and not in a "res" subfolder).
    ok now I'm even more confused that seems to go against the experiment I did in : file handling problem

    being that your not saying "res/input.txt"

    And I'm still unable to write to resource, I haven't been able to figure that out.

    Quote Originally Posted by CodesAway View Post
    Second, create a working set for each course. If there are many projects in the course, create multiple working sets, one for each of the course's different units. The working sets will allow you to see just the projects that are relevant to the current project (without cluttering your workspace).
    Third, when working on a project, select the working set for the project to view only the projects in that working set.
    How do you create working sets? just like workspaces within eclipse workspace?


    and thanks for the link I'll check that out.

  4. #4
    ChiliPepr is offline Member
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    0

    Smile Mozy

    Speaking of Mozy, MozyHome works pretty well for me on both Mac and Windows. If you ever need it, their 2nd level support is good.

    Use the following link to get 20% more space (512 Mb) on a free MozyHome 2 Gb account:

    mozy.com/?code=D685JF

  5. #5
    gcampton Guest

    Default

    Nice try, but I already signed up using codesaway link, and Welcome to the forums

  6. #6
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    6

    Default

    Quote Originally Posted by gcampton View Post
    ok now I'm even more confused that seems to go against the experiment I did in : file handling problem

    being that your not saying "res/input.txt"

    And I'm still unable to write to resource, I haven't been able to figure that out.
    There's a difference between a resource and a typical file. A resource is stored with the created project - it's part of the jar (if you export the project). A file, however, is just a file.

    Edit: as far as I know, you cannot write to a resource (since it lies in the jar, when you export the project), you can only read from it. You can read/write to a normal file, and it remains on the user's computer (even after the code is run); a resource is part of the jar (not the file system).

    The difference is that a resource is in a "SOURCE folder", whereas a file is in a "folder". If you right click on a project and go to "new", you'll see options for creating a new Java project, project, etc. Near the middle are options for "source folder" (used for resources), and "folder" (used for normal files).

    If you put the file in a "folder", then you access it as a file, which includes the "res" subfolder. If "res", however, is a "SOURCE folder", then any file in the folder is a resource, and you access it the below method.

    Java Code:
    // Access the "input.txt" resource in the ReadResource class
    InputStream inputTxt = ReadResource.class.getResourceAsStream("input.txt");
    The reason you don't use the "res" with resources is that ALL source folders are merged, and stored in the root. This includes your "src" folder (which is a "source folder"), as well as your "res" folder (and any other source folders).

    See the below screenshot for the project's layout

    Organisational EXPERTS!-readresource.png

    Java Code:
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    
    public class ReadResource
    {
    	/**
    	 * Output each line in the "input.txt" resource
    	 * 
    	 * @param args
    	 *            (not used)
    	 * @throws IOException
    	 */
    	public static void main(String[] args) throws IOException
    	{		
    		InputStream inputTxt = ReadResource.class.getResourceAsStream("input.txt");
    		BufferedReader in = new BufferedReader(new InputStreamReader(inputTxt));		
    		String line;
    
    		while ((line = in.readLine()) != null) {
    			System.out.println(line);
    		}
    
    		in.close();
    	}
    }

    Edit:
    In short, a resource is a file that's part of the project (e.g. default configuration file, language files, icons, etc.) - files that are part of the project (and should not change). Files, on the other hand, are created on the user's computer (and remain after the code has executed). For example, the user's configuration files would remain on the system (and can be modified), but the default configuration file would be part of the jar. If there was no user configuration file, you could use the default one and write it to the file system - to use as the user's configuration file.


    Quote Originally Posted by gcampton View Post
    How do you create working sets? just like workspaces within eclipse workspace?
    No, a workspace is what you load when you run eclipse - it's where ALL your code is. A "working set" filters the projects - showing you only the projects in the working set.

    To create a working set, right click while in the "project explorer" view. Go to new, select "Java Working Set".

    Organisational EXPERTS!-newworkingset.png

    From here, add the projects you want to appear in the working set, name it, and then click "Finish".


    To select a different working set, click the "inverted triangle" next to the "paw print".

    Organisational EXPERTS!-selectworkingset.png

    This opens a menu, from which you can select the working set.

    Organisational EXPERTS!-selectworkingset-2-.png
    Last edited by CodesAway; 01-05-2010 at 09:41 PM.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  7. #7
    gcampton Guest

    Default

    If you put the file in a "folder", then you access it as a file, which includes the "res" subfolder. If "res", however, is a "SOURCE folder", then any file in the folder is a resource, and you access it the below method.
    that's funny, that's what I originally tried doing worked quite well with normal file reading and writing too, so long as I appened the folder name.

    What I don't get is if I have something my program uses say a file that acts as a database that i read in when my program starts and stick say 500 or so lines into 500 odd element in an arraylist, program to modify the array while executing, and then perhaps write back to the file with the new database when user logs out.

    So even if something of this size that is relatively small (say an encrypted password file) I don't understand where I'm supposed to put these and the best way to access them for reading and writing. I kinda get the point of reading as getResourceAsStream(), (mostly that it's easier for the Java environment to find it).. but it has limited uses...

  8. #8
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    6

    Default

    Quote Originally Posted by gcampton View Post
    What I don't get is if I have something my program uses say a file that acts as a database that i read in when my program starts and stick say 500 or so lines into 500 odd element in an arraylist, program to modify the array while executing, and then perhaps write back to the file with the new database when user logs out.

    So even if something of this size that is relatively small (say an encrypted password file) I don't understand where I'm supposed to put these and the best way to access them for reading and writing. I kinda get the point of reading as getResourceAsStream(), (mostly that it's easier for the Java environment to find it).. but it has limited uses...
    A resource is read-only - since it's stored in the exported jar. This is meant for themes, language files, program icons, and other files that are part of the program, but don't need to be modified. Storing them as a resource (versus as files) has several benefits: 1) they remain in the jar (so only a single file, versus many), and 2) they are compressed (since a jar is a compressed archive file).


    A database, on the other hand, is something that changes (much like configuration files). Java offers several options, depending if you want to store the files in the application folder (where the jar resides), or the user's profile. The first means that all users share the same database/settings. The latter means that each user will have a separate database/settings.

    In both cases, you want to use System.getProperty(String key).


    If you want the file to reside in the same path as the jar, use System.getProperty("user.dir"). This path is where the jar file is located. When executing in Eclipse, this directory is the project's directory. For example, "E:\Data\Java_Workspace\Test" is what it returned for me, since my workspace is "E:\Data\Java_Workspace" and the project's name is "Test". Note: the same path is used, regardless which package the Class is located.

    If you want the file to reside in the "user's home" directory, use System.getProperty("user.home"). When I ran the code, I got "C:\Users\Me". The "C:\Users" is because I'm running Vista. and "Me" is my username (yes, that's my actual username).


    Even though I'm running this on a Windows computer, the miracle of Java means that these values will be set to the correct value for whatever operating system the code is run. So, on a Mac you will get different values, similarly you get different values on Windows XP.

    You can use these values to store configuration files (e.g. a database) either in the application's directory (to be shared across all users), or in the "user's home" directory, so that each user has their own.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  9. #9
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    I just thought that a discussion of code organization is not complete without mentioning build tools like ant and maven. Also take to write (and organize) code assuming a deploy environment rather than a development envirenment.
    While code is written in IDEs, it is not meant to run there forever.

  10. #10
    gcampton Guest

    Default

    Quote Originally Posted by r035198x View Post
    I just thought that a discussion of code organization is not complete without mentioning build tools like ant and maven. Also take to write (and organize) code assuming a deploy environment rather than a development envirenment.
    While code is written in IDEs, it is not meant to run there forever.
    Doesn't the IDE just emulate a deploy environment anyway? hence source folders dissapeering on Jar creation, and use of getResourceAsStream etc...
    --------

    @Codes, thanks for clearing that up, I guess the original topic called "file handling problems" Fubarable must not have realized I was trying to write to these files as well, which is why I was so confused.

Similar Threads

  1. Replies: 15
    Last Post: 09-18-2009, 09:45 AM
  2. For JSP & JAVA experts -help me please
    By java student in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-27-2008, 12:40 AM
  3. For java experts -help me please
    By java student in forum Advanced Java
    Replies: 1
    Last Post: 05-25-2008, 07:37 AM
  4. Hello Java Experts :)
    By mark-mlt in forum Introductions
    Replies: 2
    Last Post: 04-17-2008, 11:58 AM
  5. Java experts needed- 30 minute online Java projects
    By michelle in forum Jobs Offered
    Replies: 0
    Last Post: 03-06-2008, 12:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •