|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Java, what is char mainly used for?
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
nVidia Enthusiast
|
Other than for switches, I really haven't found any uses for char. My book doesn't explain much about char, and google didn't turn up any results(or at least results I could understand
). Also why is char needed? I just want to know if I'm missing something big about not knowing how to use char that's all, all help will be very appreciated!![]()
__________________
"We are all prophets, that is why we make so many mistakes" "One who wears a mask wants to become someone else one who wears a mask somewhere other than the face wants to become many" "The truth is a lie" "There are only a few free people in the world, the insane"
|
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
Apple Doesn't Love You
|
Flags, various uses pertaining to strings, plenty of stuff
Admittedly char's are not as powerful in java as in other languages. C, for example, does not have strings, but rather arrays of char's (java's string class is really pretty much just that, but there is a separate class for it). That question is very hard to answer tho - kinda like "what do I use a nail for?" Depending on what you need to do you may have a hundred uses for chars or none
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
nVidia Enthusiast
|
The reason why I asked is because even though I'm a newb, if I were to make a program with Java I wouldn't think of using chars. I was wondering if that would be a problem thats all
__________________
"We are all prophets, that is why we make so many mistakes" "One who wears a mask wants to become someone else one who wears a mask somewhere other than the face wants to become many" "The truth is a lie" "There are only a few free people in the world, the insane"
|
|||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
Apple Doesn't Love You
|
No - if you don't need char's that isn't a problem. Remember too that while you're learning the programs you create do more or less nothing. The scope is so small that it isn't surprising that you don't need some stuff
|
|||||||||||||
|
|
|
|
#5 (permalink) | |||||||||||||
|
Jack of all trades
Join Date: Mar 2007
Location: Cambridge, Ontario
Posts: 3,562
Rep: 271
![]() ![]() ![]() Unique Rep: 208
Trader Rating: 2
|
I personally use chars as a catch, or a break from a loop. so a conditional flag. You can do it without using chars though...
__________________
I am 91% addicted to Counterstrike. What about you? ![]() OCN CS:S GG: overclock.nuclearfallout.net:27015 OCN TF2: 8.9.16.94:27015 (temporary) [CSS GUN GAME ADMIN] Ban Hamma of Pwnage +5 skillz [TF2 ADMIN] Ban Hammer of scouting + 20 scout powaz
|
|||||||||||||
|
|
|
|
#6 (permalink) | ||||||||||||||
|
Photography nut
![]() |
Like rabidgnome229 basically already said. In languages like C/C++ (and many others), there are no strings, in the java sense of a string. So to have a string in those languages you create an array of characters. Java does the same thing but it happens behind the scenes and you don't have to worry about it. There is a String class is java that takes care of that. I don't use chars that often either, I tend to use boolean instance variables as flag, unless their are many option and then usually I try using an array to manage the objects, so then I'm dealing with integers.
It just all depends on the task at hand and how you think about solving the problem. There is nothing wrong with not thinking to use chars in a situation though.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
|
|
#7 (permalink) | ||||||||||||||
|
nVidia Enthusiast
|
Quote:
![]()
__________________
"We are all prophets, that is why we make so many mistakes" "One who wears a mask wants to become someone else one who wears a mask somewhere other than the face wants to become many" "The truth is a lie" "There are only a few free people in the world, the insane"
|
||||||||||||||
|
|
|
|
|
#8 (permalink) | ||||||||||||||
|
Photography nut
![]() |
Code:
try{
if(num<0)
throw new NegitiveNumberException();
/**Code*/
}
catch(NegitiveNumberExceptio e){
System.out.println(e.getMessage());
}
String word=""
String lineInDatabase="3; cups; suger";
for(int i=0;i<lineInDatabase.length;++i){
if(lineInDatabase.chatAt(i)!=';')
word+=lineInDatabase.charAt(i);
}
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
|
|
#9 (permalink) | ||||||||||||||
|
nVidia Enthusiast
|
Quote:
Any way Thank You![]()
__________________
"We are all prophets, that is why we make so many mistakes" "One who wears a mask wants to become someone else one who wears a mask somewhere other than the face wants to become many" "The truth is a lie" "There are only a few free people in the world, the insane"
|
||||||||||||||
|
|
|
|
|
#10 (permalink) | ||||||||||||||
|
Photography nut
![]() |
![]() I had to write a program for a class that managed a database of recipes, and was able to add files thats contained a recipe's list of ingredients in that order: quantity; measure; name. So it was just fresh in my mind.
__________________
"UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever things." - Doug Gwyn Try out the latest Programming Challenge Quote:
CPU-Z Validation @ 2.97-prime95 stable 16 hours @ 1.48v Proof | CPU-Z Validation @ 3.15 Getting Mouse Side Buttons to work in Linux, Compile a custom Kernel, More
|
||||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|