• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting a drive label  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been playing around with a snippet I wrote to get the Label on a drive (below). It works fine for me (though I will take any constructive criticism). My question is whether the is a way to set the drive label, purely with Java. I know I could call command line, or even resort to using the Windows API, just curious if I am overlooking a simply way to do so without going that route.

 
Sheriff
Posts: 4748
133
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your main language Perl? In Java, you shouldn't use a sigil ($) in front the variable name. No $dir, just dir.
 
Knute Snortum
Sheriff
Posts: 4748
133
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I general, I prefer



over

 
Jeremiah Logan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Knute, thanks for the responses. I do come from other languages, so the $ moniker is habit. Can you expound on why this is an issue in Java? I have not found anything in any docs that explains where/how it would cause issues (but if there are, I would certainly like to know about them now ).
 
lowercase baba
Bartender
Posts: 12613
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
as far as I know, it's more a matter of convention than anything else. Java developers aren't used to seeing it, so it looks 'odd' to them.

I do a lot of perl and java, and it takes me a bit to make the mental switch myself, but I do agree that in java, the '$' do look a little strange, even though it is legal in an identifier.
 
Knute Snortum
Sheriff
Posts: 4748
133
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing more than convention and a bit of confusion by people who read your code. In general, anything that confuses most people is not recommended.

"All things are lawful for me, but not all things are profitable."
 
Jeremiah Logan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, gentlemen, fair enough.
 
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:I general, I preferover


Those two aren't actually equivalent.
The more readable version would be
 
Knute Snortum
Sheriff
Posts: 4748
133
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's true the true statements aren't equivalent, but i starts off at zero and is only incremented, so the two states are 0 and >0. i == 0 is more natural as i <= 0 makes you wonder what i < 0 means and how it would get that way.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case you're correct, but I was speaking more generally in case someone read your post without looking at the OP's original code and thought the two statements were equivalent
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!