Backing up Java? - java

I'm currently using Java and I'm looking for a program that saves a new version of what I'm doing each time I compile. I don't mind if it doesn't run, I can go in and edit the class name to make it match the .java name afterwards. As I'm a beginner, I keep getting caught by overextending myself and then breaking the project I'm working on irreparably. I'm just looking for a way to go back to a safe state.
I'm sure their are programs for this, but because I don't know the collective noun for them, finding one is next to impossible.
All help is much appreciated.

What you're looking for is revision control. This works independent of the language you're dealing with, since all the VCS is concerned with is the state of the software at a particular snapshot in time.
Some recommendations:
Subversion
Git
Mercurial
IntelliJ IDEA also comes with a built-in local revision system, which allows you to visit a particular file's history. It'd still be preferable to use either Git or Subversion.
There are also sites that you can host your project on to better preserve your project, such as Github or Google Code. Github uses...Git, but Google Code will allow you to use a few others, such as Subversion and Mercurial.

Use a Dropbox folder. If you use Eclipse, just put the entire folder in the Dropbox folder, and you are set to go with a backup-ed IDE.
Added bonus: access your project from anywhere.
You could also use GitHub, but then your source code will be open to the community unless you pay for one of their "plans".
Also, consider using Bitbucket, which isn't known as well, but is free. (Thanks to A--C for that alternative to GitHub)

Related

Using Libraries In Netbeans Java With Ant

This is my first StackOverflow question, and I'm also a Grade 12 student, so apologies if it is a stupid one - feel free to let me know if it is, however, after numerous hours searching the internet, I can't find an answer to this.
this is not homework help.
Background
I am currently writing a program in Netbeans that will deal with large COVID datasets, and I'm looking to use some external libraries to make operations easier. The ones I've looked at are
https://github.com/jtablesaw/tablesaw and https://github.com/nRo/DataFrame.
However, I have only ever used "Java with Ant", and both of these GitHub's only mention using the library through Maven dependencies in the pom.xml file. I have never used Maven, and I am very unfamiliar with Build Tools in general. As when I was introduced to Java, my teacher instructed me to use Java with Ant. That being the case, any time I have used an external library before I have simply added the .jar files into my library folder and used
import foo.bar; or import foo.*; to use the libraries.
My question
Is there a way for me to use either of these libraries without switching build tools? For example, download the source and make the .jar's in a way that isn't overly tedious, so that I can use the libraries the same way I am used to? Or, perhaps something I'm missing that allows me to download them in that format? If not, seeing as almost every Github library I find instructs me to use it through Maven dependency, should I stop using Java with Ant altogether and start learning how to write programs using Maven?
Any insight is greatly appreciated. If this has already been answered, feel free to link the answer and sorry for cluttering up the forum. Thanks.
From one of the Maven websites you can download the libraries and use them as normal. First find the artifact page, for example using mvnrepository.com as shown below, or you could use the https://search.maven.org/:
Find the relevant page by searching for the artifact, then once there you can choose the version:
Then click on "View all" to see the artifact jar files:
Then lastly right-click the file you need and choose save:

How to download Packages for Android Studio?

I just started Android Development yesterday and just finished with my first Activity. On running it, I'm getting errors like
**Error:(4, 37) error: package android.support.design.widget does not exist**
As I never post without it, I've already done plenty of searching on this. Basically, what I've understood is that it couldn't find that Widget Package on my PC. So, do I have to download it? If yes, then how?
People on internet had similar problem with Packages and almost every post has different answer to this. Some say change your Gradle File others say Update your Studio (have done it).
Any kind of explanation or bit of knowledge with the solution would be highly appreciated. I'm a kind of geek who want to get concepts and basics clear. So, it would be great if you include the reason and technicality behind this too with your answer. Thanks. :)
It's a design library for Android apps development and as #Dominique pointed have a look at that page and copy paste that compile 'com.android.support:design:22.2.0' line in your project gradle file and press the sync button. Your project will sync in a few moments and the design library will be downloaded. Now you can use this library and there won't be any errors.
No, in Java "package" is not a "library" or a "piece of software" (like it is in some other languages). Package is what classes belong to - you might think of packages as directories containing Java files (it is a simplification, but it works). In Java libraries are packaged into (usually) "jars" (those jars usually contain classes divided into packages), so what you need to download is "jar".
So, first thing you need to check is: what library contains the package, and configure your IDE accordingly. The package in question belongs, I think to the so called android support library, which you can install using the SDK tool.

How to accommodate multiple coding styles? (git vs. IDE)

I am collaborating on a git-sourced, maven-managed Java project with differing code styling preferences with users using multiple IDE's (note 1).
Is there a tool or IDE configuration that will allow code to be viewed and edited using style-1, but committed to SCM using style-2?
My research points me to 'no', but a solution combining git hooks and Checkstyle/jrefactory might be possible.
So if 'no' to above, is there a tool/process that will perform the TBD process actions below?
The checkout process flow for User1 would be:
git pull
TBD process formats code to User1 style-1
User1 works in their preferred IDE with style-1 settings
The commit workflow for User1 would be:
User1 is ready to commit/push code
TBD process formats code to standard format style-standard
git push
Note 1: multiple IDE's = Eclipse, IntelliJ, Netbeans.
Note 2: My question differs from this question in that I'd like to focus on an IDE-related solution, since forcing the minority of standards-divergent users is probably a more efficient solution.
Note 3: Acknowledging that this shouldn't be done for best-practices-reasons. However, if you grant that it's time expect more flexibility from our IDEs and SCMs, this question is intended to explore those solutions.
First of all, you really shouldn't do that. Codestyle wars are bad for any project, and it is best to decide upon one codestyle that everybody must use. It is simple to configure IDEs to automatically apply the specified codestyle at every filesave, so the developers don't have to write code in the target codestyle themselves, they can let the IDE do that for them. True, this doesn't solve the fact that they'll have to read code in a codestyle they don't yet like, but it's a lot safer than having invisible automatic code changes; that's a major source of bugs.
Maybe you can use Eclipse's code formatter from the command line to apply a different codestyle. You'd have to set up git hooks, make sure everybody has Eclipse available, and provide the proper configuration files for their preferred codestyle. You'd need hooks both for post-checkout and pre-commit, one to set up the user's codestyle, the other to commit in the central codestyle. To go one step further, you can play with the index to add the formatted code so that it doesn't include style differences in git diff (although they will show up in git diff --staged).
Again, you shouldn't do that.
I agree with Sergiu Dumitriu in this not being a very good idea. But still git provides exactly what you are looking for. Even though this will only work if your central coding style is very well defined and strictly followed. Here’s how it works:
Git provides smudge/clean filters. They allow you to pass all code through a so-called “smudge” filter on checkout and reverse that with a “clean” filter when code is added to the staging area. These filters are set in .gitattributes, and there is a repository-local version of that file available in .git/info/attributes.
So you set your smudge filter to a tool that will change the code to your personal coding style on checkout:
And your clean filter will convert the code back to the central coding style on checkin (more precisely: when file are staged):
It is very important, that smudge -> clean is a no-op / generates the original file again. Otherwise you will still check in format changes every time you change a file.
Using smudge and clean filters will retain all the functionality of git (including git diff etc). You can find the full docu in git help attributes

Is there a tool to see check-ins for all projects in Subversion by commit date and commit person

I want to know If there are any plug-ins or tools to see the files commited to the subversion by date and committer.
we are using subversion. It will be nice, If its like a web app.
Please suggest If there are any other alternative ways to do this also.
Its for my manager. So cannot be through eclipse. :)
websvn offers a nice access to svn via web.
It offers RSS feed support so your boss gets notified on every commit.
As a commercial tool fisheye might be worth a look.
Have you tried displaying the SVN log, using any SVN client (like TortoiseSVN, I guess your PHB is using Windows)? You can easily see the time, comments and author of any given SVN commit there...
See:
http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-showlog.html
Since TortoiseSVN integrates nicely into Windows Explorer, even your manager should be able to use it...
That being said, it's trivial to access the log information, for example using pysvn, and displaying it in a simple GUI, if selecting and opening the revision log via the context menu is asking too much in your given use case...
You can also take a look at svnmonitor. It will keep checking for new changes, and notify the user (this can be configured)
Trac is a wiki and issue tracking system that works well with subversion. As an example, click on the project's Browse Source link.

Is there a decent tool for comparing/diffing two Java packages?

I'm looking for a tool that will give me a high level view of which files are different between two fairly large Java packages. If I could then drill down into individual files then that would be good. I don't want to go file by file if possible.. any ideas?
thanks
Beyond compare (and other diff tools) can do directory compares too ...
If you're more interested in API differences than content differences, check out JDiff.
For example the Google Guava project uses it to show changes between releases. Here is the r06 release diff: http://guava-libraries.googlecode.com/svn/tags/release06/javadoc/jdiff/changes.html
WinMerge is an excellent Windows standalone diff tool and I use it for almost all of my source files. It can navigate through folder structures (in your case, your Java packages).
If you do use version control, it integrates very well with TortoiseSVN (and perhaps others in the Tortoise family).
You can use pkgdiff tool to compare java archives:
pkgdiff A.jar B.jar
See sample report for args4j.
See also japi-compliance-checker for analysis of API changes in your java archives.
I use Kompare on Linux. Just a diff GUI front end, that can diff directories recursively. I believe there are many others (I'm sure I've seen a list somewhere).
Eclipse works well. Just select the two different packages (hold the Ctrl key, click on a package, click again on the other package), right click on one of the selected packages, go to the 'Compare With...' submenu, select 'Compare With Each Other'.
I have used Araxis Merge to do this too. It is also helpful for doing code merges. It is not free (about 80 bucks I think) but well worth it.
I always use eclipses team synchronize (for included cvs; this requires one revision checked in and another one disk) works same way with subclipse plugin for subversion.
If you are on windows and don't have the checked in a version control system you could use winmerge
Last I checked kdiff3 worked both on *nix and windows.

Categories