Sect. 18) How can I set a system property?
Java Programmer's FAQ - Part DJDK 1.2 has System.setProperty( "property", "new value" ); Until then, you can get all the properties, and set just the one you want with code like this: System.getProperties().put("property", "new value" );
Related QuestionsSect. 18) What are the naming conventions?
Java Programmer's FAQ - Part DPackage names are guaranteed uniqueness by using the Internet domain name in reverse order: com.javasoft.jag - the "com" or "edu" (etc.) part used to be in upper case, but now lower case is the recommendation. Class and interface names are descriptive nouns, with the first letter of each word capitalized: PolarCoords. Interfaces are often called "something-able", e.g. "Observable", "Runnable", "Sortable".
Related QuestionsSect. 18) How do I convert a String to an int?
Java Programmer's FAQ - Part DThere are several ways. The most straightforward is: String myString = numString.trim(); int i = Integer.parseInt(myString); long l = Long.parseLong(myString) or String myString = numString.trim(); i = Integer.parseInt(myString,myIntRadix); Note 1: There is a gotcha with parseInt - it will throw a NumberFormatException for String values in the range "80000000" to "ffffffff". You might expect it to interpret them as negative, but it does not. The values have to be "-80000000" .
Related QuestionsSect. 18) How do I convert an int to a string?
Java Programmer's FAQ - Part DTry any of these: String s = String.valueOf(i); or String s = Integer.toString(i); or String s = Integer.toString(i, radix); or // briefer but may result in extra object allocation. String s = "" + i; Note: There are similar classes for Double, Float, Long, etc.
Related QuestionsSect. 18) How do I execute a command in my program?
Java Programmer's FAQ - Part DUse Runtime.getRuntime().exec( myCommandString ) where myCommandString is something like "/full/pathname/command". An applet will need to be signed in order to allow this. If the pathname contains spaces, e.g. "c:\program files\windows\notepad", then enclose it in quotes within the quoted string. Or pre-tokenize them into elements of an array and call exec(String[] cmd) instead of exec(String cmd). From JDK1.3 there are two new overloaded Runtime.exec() methods.
Related QuestionsSect. 18) How do I manipulate bits in Java?
Java Programmer's FAQ - Part DUse bytes, shorts, chars, ints or longs if you need to manipulate no more than 64 bits at once. Use ~ for NOT, & for AND, | for OR, and ^ for XOR. Beware that the precedence for & | and ^ is not intuitive; they have lower precedence than == and !=, so you must write: if ((a & 1) == 1) rather than: if (a & 1 == 1) You can also shift bits with the <<, >> and >>> operators; >> is a signed shift and >>> is an unsigned shift.
Related QuestionsSect. 18) How can I clone using serialization?
Java Programmer's FAQ - Part DLook at the code below, submitted by expert programmer John Dumas. It uses serialization to write an object into a byte array, and reads it back to reconstitute a fresh copy. This is a clever hack! import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; import java.io.ObjectOutputStream; import java.io.
Related QuestionsSect. 18) Why can't I get String mutator methods to work?
Java Programmer's FAQ - Part DCode like this seems to show that the calls don't work! String s = " hello "; s.trim(); s.toUpperCase(); Note again that Strings are immutable. This means that once a String has been initialized, its contents won't change. In the code above, the method calls return a different String with the desired alterations. But this new String is not assigned to anything, so the results are discarded. To see the changes, assign the results of the method call to the original String or to another String.
Related QuestionsSect. 18) How do I print the hex value of an int?
Java Programmer's FAQ - Part DYou can print the hex equivalent of an int with: int i = 0xf1; System.out.println("i is hex " + Integer.toHexString(i) );
Related QuestionsSect. 18) How can you send a function pointer as an argument?
Java Programmer's FAQ - Part DSimple answer: use a "callback". Make the parameter an interface and pass an argument instance that implements that interface. public interface CallShow { public void Show( ); } public class ShowOff implements CallShow { public void Show( ) { .... } public class ShowOff2 implements CallShow { public void Show( ) { .... } public class UseShow { CallShow savecallthis; UseShow( CallShow withthis ) { savecallthis = withthis; } void ReadyToShow( ) { savecallthis.
Related QuestionsSect. 18) How do I do I/O redirection using exec()?
Java Programmer's FAQ - Part DThis solution works on Unix platforms using either JDK 1.0.2, or JDK 1.1. The trick is to use an array of Strings for the command line: String[] command = {"/bin/sh", "-c", "/bin/ls > out.dat"}; If you don't do this, and simply use a single string, the shell will see the -c and /bin/ls and ignore everything else after that. It only expects a single argument after the -c. import java.io.*; import java.util.
Related QuestionsSect. 18) So why can't I exec common DOS commands this way (as in 18.8)?
Java Programmer's FAQ - Part DThe reason is that many of the DOS commands are not individual programs, but merely "functions" of command.com. There is no DIR.EXE or COPY.EXE for example. Instead, one executes the command processor (shell) explicitly with a request to perform the built-in command, like so: Runtime.getRuntime().exec("command.com /c dir") for example. On NT, the command interpreter is "cmd.exe", so the statement would be Runtime.getRuntime().
Related QuestionsSect. 18) OK, how do I read the output of a command?
Java Programmer's FAQ - Part Dabove (18.8, 18.9), adjusted like this: BufferedReader pOut= new BufferedReader( new InputStreamReader(p.getInputStream())); try { String s = pOut.readLine(); while (s != null) { System.out.println(s); s = pOut.readLine(); } } catch (IOException e) { } Another possibility is to read chunks of whatever length as they come in: ... p = r.exec(cmd); InputStream is = p.getInputStream(); int len; byte buf[] = new byte[1000]; try { while( (len = is.
Related QuestionsSect. 18) What is the point of creating the temporary reference to this.layoutMgr?
Java Programmer's FAQ - Part DThis code is from the 1.0 AWT, and the programmer was probably pretty skilled. public synchronized void layout() { LayoutManager layoutMgr = this.layoutMgr; if (layoutMgr != null) { layoutMgr.layoutContainer(this); } } The code makes a local copy of a global variable for one or both of two reasons. The first reason is that accessing local variables can be faster than accessing (non final) member variables. It's good for loops or where there are many references in the source.
Related QuestionsSect. 18) What is the difference between "a & b" and "a && b" ?
Java Programmer's FAQ - Part Da & b" takes two boolean operands, or two integer operands. It always evaluates both operands. For booleans, it ANDs both operands together producing a boolean result. For integer types, it bitwise ANDs both operands together, producing a result that is the promoted type of the operands (i.e. long, or int). "|" is the corresponding bitwise OR operation. "^" is the corresponding bitwise XOR operation. a && b" is a "conditional AND" which only takes boolean operands.
Related QuestionsSect. 18) How can I get a globally unique ID in Java?
Java Programmer's FAQ - Part DThe only way in pure Java to create globally unique ids is to set up a server, accessible by all interested parties, which supplies the ids. There are classes in Java which may supply 'probably' unique ids, with varying levels of reliability --- but a dual processor machine with two JVMs running could easily generate duplicate ids. Note that a global server issuing a token (and periodic "are you still using it" messages) is a pretty good way to do cooperative file locking too.
Related QuestionsQ 18 What about furnishing my property?
Questions and AnswersMany developers offer furniture packs. Alternatively, there is a wide range of furniture shops for you to explore.
Related QuestionsSect. 18) Do I really need to use new String(...) to create a new String?
Java Programmer's FAQ - Part DNo. A String constant such as "" or "hello" is already a String, so there's no need to write code like: String s = new String(""); You can instead write the simpler String s = ""; Note that Strings are immutable (unchangeable), so there is no danger of accidentally modifying a String that is pointed to by another reference.
Related QuestionsCan I rent through First Avenue Property Management Ltd if I am under 18?
First AvenueUnder the Residential Tenancies Act, minors are prohibited from entering into tenancy agreements. To discuss this further please contact one of our friendly Property Managers.
Related QuestionsWhy are our age limits set at 16 for piercing and 18 for tattoos?
Way Cool Uptown ++Under Ontario law, what we do is considered a penetrative act and, unfortunately, falls under the Age of Consent laws. These laws state that a person must be 16 or over to consent to said act provided that the person performing the work is over the age of 18. As well, the legal age to sign medical consent for unnecessary procedures without parental permission is 16.
Related QuestionsDo I have to be 18?
Frequently Asked QuestionsYES. Recent changes to the United States Parachute Association require all tandem passengers to be 18 years of age. You also need to be 18 to sign our waiver as a binding contract. You also must be 18 years of age to participate in AFF or Static Line Jumps.
Related QuestionsWhy is this a 18+ show?
Smallbang F.A.Q | Frequently Asked QuestionsThe band will try to play as many All Ages shows as they can, but there are certain laws and rules that certain clubs have that prevent this. If there is ever an age restriction at a show, it is not because the band wants it that way, it's because it has to be that way or else they cannot play there....Back To Top
Related QuestionsWhy must I be over 18?
Dating service FAQ sectionThis is standard practice I'm afraid, there are not hardly any sites that cater for under 18's in this way. While the site is of a Dating nature the things often discussed say in the chatroom might not be suitable for those under 18. That is not to say that the site contains in any way anything that is not really family orientated. amormatch.com always strives to make sure that profiles and the chatroom are clean, and moderators may be appointed to ensure this is the case.
Related QuestionsSkydive KapowsinNO. We allow you to jump if you are 16 years old as long as you have parental permission. That either means that you parent must be here to sign the waiver with you or you need to download a copy of our waiver and have it signed and notarized by your parent.Related Questions
What if I am under 18?
CSSD SHORT COURSES - FAQSYou may receive a concession if you are an EU resident, a dependant of an EU resident, registered as a full time student or in receipt of state benefit. You must apply for the concession and provide us with the appropriate evidence.
Related QuestionsWhat's up with 18 and over?
Indigo - Humboldt County's Premiere Nightclub!and over is on certain nights, as well as during certain special events such as concerts or shows. The calendar of events on the website will list whether a event is 18 and over or 21 and over. On the nights we allow 18 and over, 2 rules apply: There are absolutely no In & Out privileges for under 21. If you leave, you will have to pay to re-enter.
Related QuestionsWhat about these books: Unharmed, A Fine Set of Teeth, 18, Breaking and Entering?
The Official Website of Jan BurkeUnharmed" and "A Fine Set of Teeth" are short stories which were available in bound, limited editions produced by ASAP Publishing. These are signed collectors' editions. The book 18 is a collection of Jan's short stories. Breaking and Entering is a booklet about getting published; Jan edited the first edition of the booklet for Sisters in Crime. There is now a new edition available, edited by Denise Swanson.
Related Questions