Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

newbie version control

Thread view: 
Ueland - 04 Nov 2005 14:18 GMT
Hi I'm a newbie using winXP and working from console (no IDE). I've
started to experiment with simple classes and objects. As I understand
the name of the class must be same as the name of the file so if I
declare
  class Point {...}
then I should save the file as Point.java

Let's say I've done that and now I want to test a new feature without
erasing the old version. So I want to save the new file version as
Point2.java. But this forces me to change all occurances of  Point to
Point2, that is the classname, the constructors and so on.
  class Point2 {...}

Is there any SIMPLE way to make different versions without having to
change the class name. (I've thought of using different packages but
that also complicates things).

Thanks Bob
Daniel Dyer - 04 Nov 2005 14:31 GMT
> Hi I'm a newbie using winXP and working from console (no IDE). I've
> started to experiment with simple classes and objects. As I understand
[quoted text clipped - 12 lines]
> change the class name. (I've thought of using different packages but
> that also complicates things).

Two really easy ways spring to mind.  First you can just take a copy of  
your whole source tree and work on that.  Secondly, you could just rename  
the old file out of the way and make, call it something like  
"Point.java_old" so that it doesn't get picked up by the compiler but is  
still there and can be reverted to it's old name if you want to use it  
again.

This is a reasonable approach as you are getting started, but eventually  
you will want to look into something like Subversion or CVS.

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk

Roedy Green - 04 Nov 2005 14:31 GMT
>Is there any SIMPLE way to make different versions without having to
>change the class name. (I've thought of using different packages but
>that also complicates things).

no. Later in your career you will learn  to use a version control
system so you can maintain several branches.  See
http://mindprod.com/jgloss/cvs.html

the best you can do now is save under a variety of names, and copy one
of the old ones onto Point.java when you want to make it the active
version.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Roedy Green - 04 Nov 2005 15:15 GMT
On Fri, 04 Nov 2005 13:31:26 GMT, Roedy Green
<my_email_is_posted_on_my_website@munged.invalid> wrote, quoted or
indirectly quoted someone who said :

>the best you can do now is save under a variety of names, and copy one
>of the old ones onto Point.java when you want to make it the active
>version.

another way to do it is something like this:

xcopy *.* C:\version32
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

zero - 04 Nov 2005 15:39 GMT
"Ueland" <bobueland@yahoo.com> wrote in news:1131110326.622630.218450
@z14g2000cwz.googlegroups.com:

> Hi I'm a newbie using winXP and working from console (no IDE).

Good!  That's the best way to learn to write clean code.  Later you may
use an IDE to be able to work faster, but to learn you should work with
a simple editor and compile from the command line.

> I've
> started to experiment with simple classes and objects. As I understand
[quoted text clipped - 12 lines]
> change the class name. (I've thought of using different packages but
> that also complicates things).

Sure, you just rename the old version.  You can automate this with the
following Java program:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

public class VersionControl
{
  public static void main(String[] args) throws Exception
  {
     File fFile = new File(args[0]);
     int counter = 0;
     File fDest = new File(args[0] + "." + counter);
     while(fDest.exists())
        fDest = new File(args[0] + "." + ++counter);

     FileChannel in = null, out = null;
     try
     {
        in = new FileInputStream(fFile).getChannel();
        out = new FileOutputStream(fDest).getChannel();

        in.transferTo( 0, in.size(), out);
     }
     finally
     {
        if (in != null)
           in.close();
        if (out != null)
           out.close();
     }
  }
}

Just compile this, and run it like this:
java VersionControl Point.java

This will create a copy of Point.java on which you can work, and the old
version will be saved as Point.java.0  On subsequent calls you'll get
Point.java.1, Point.java.2, etc.

As an exercise, try to figure out how VersionControl works.  Add a fail-
safe in case you forget to enter the filename as argument.  Also add
some code to recover from I/O errors while trying to copy the file.
Ueland - 04 Nov 2005 18:54 GMT
Thanks, I'll certainly try this! I also came up with this simple
solution.

I create a batch filecalled point.bat

@echo off
xcopy %0%1 %0%2 /I
cd %0%2
cedt *.java

I put this file in C:\jex which is the root for my source code. Suppose
now that the files for my point project is  inside the directory point1
(which is inside the root C:\jex). When I write
> point 1 2
my batch file automatically creates the directory point2 which contains
a copy of all files in point1 directory. It also automatically makes
point2 my working directory (so that I can compile and run easily). It
also automatically opens all the new .java files in my favourite text
editor (Crimson editor cedt.exe).

(You can use your own favourite text editor but you must update the
Path environment variable so that it contains the path to your text
editor, and change cedt for something else, like TextPad if that is
your text editor).

Next time I want to work on a new version I go to the root (C:\jex) and
write
> point 2 3
and so on.

Suppose now that I now start a new project called circle. I put all my
files inside the directory circle1 and make a copy of point.bat and
call it circle.bat. I don't have to change anything inside the bat
file.

This could be improved, so that I could have only one bat file instead
of one for each project, but I'm not a DOS wizard. Any ideas in this
direction would be appreciated.

Thanks Bob
zero - 04 Nov 2005 19:01 GMT
"Ueland" <bobueland@yahoo.com> wrote in news:1131126869.064296.63100
@o13g2000cwo.googlegroups.com:

> Thanks, I'll certainly try this! I also came up with this simple
> solution.
[quoted text clipped - 36 lines]
>
> Thanks Bob

I'm not a dos wizard either, that's why I used the Java program ;-)
The drawback to your batch file is that you need to know what numbers to use.  
But otherwise it's certainly a workable solution, good thinking :-)
jussij@zeusedit.com - 14 Nov 2005 02:10 GMT
> Is there any SIMPLE way to make different versions without
> having to change the class name.

I can think of at least two ways to achieve this result.

Option 1) Use version control

Option 2) Use the file system
 c:\my projects\version1\Point.java
 c:\my projects\version2\Point.java
 ....
 c:\my projects\versionX\Point.java

Jussi Jumppanen
Author: Zeus for Windows Programmer's IDE
http://www.zeusedit.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.