Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

My solution on Ubuntu 10.04 using java-sun 1.6.0_24 having all jars in "lib" directory:
***
java -cp .:lib/* my.main.Class
***
If this fails, the following command should work (prints out all *.jars in lib directory to the classpath param)
***
java -cp $(for i in lib/*.jar ; do echo -n $i: ; done). my.main.Class
***
3 years ago
The synchronized keyword prevents concurrent access to a block of code or object by multiple threads. All the methods of Hashtable are synchronized, so only one thread can execute any of them at a time.

When using non-synchronized constructs like HashMap, you must build thread-safety features in your code to prevent consistency errors.
3 years ago
Switches based on integers can be optimized to very efficent code. Switches based on other data type can only be compiled to a series of if() statements.

For that reason C & C++ only allow switches on integer types, since it was pointless with other types.

The designers of C# decided that the style was important, even if there was no advantage.

The designers of Java apparently thought like the designers of C.
3 years ago
There is a static nested class, this [static nested] class does not need an instance of the enclosing class in order to be instantiated itself.

These classes [static nested ones] can access only the static members of the enclosing class [since it does not have any reference to instances of the enclosing class...]

code sample:
***
public class Test {
class A { }
static class B { }
public static void main(String[] args) {
/*will fail - compilation error, you need an instance of Test to instantiate A*/
A a = new A();
/*will compile successfully, not instance of Test is needed to instantiate B */
B b = new B();
}
}
***
3 years ago
I got this error and found that my PATH variable (on Windows) was probably changed. First in my PATH was this entry:
***
C:\ProgramData\Oracle\Java\javapath
***
...and Eclipse ran "C:\ProgramData\Oracle\Java\javapath\javaw" - which gave the error. I suspect that this is something that came along with an installation of Java 8.

I have several Java versions installed (6,7 and 8), so I removed that entry from the PATH and tried to restart Eclipse again, which worked fine.

If it's doesn't work for you, you'll need to upgrade your JDK (to the Java versions - 8 in this case).
3 years ago
This will probably give you what you want:
***
NSLocale *locale = [NSLocale currentLocale];

NSString *language = [locale displayNameForKey:NSLocaleIdentifier
value:[locale localeIdentifier]];
***
It will show the name of the language, in the language itself. For example:
***
Français (France)
English (United States)
***
3 years ago
You can control this via HTTP header by adding Access-Control-Allow-Origin. Setting it to * will accept cross-domain AJAX requests from any domain.

Using PHP it's really simple, just add the following line into the script that you want to have access outside from your domain:
***
header("Access-Control-Allow-Origin: *");
***
Don't forget to enable mod_headers module in httpd.conf.
3 years ago
JSON.stringify turns a JavaScript object into JSON text and stores that JSON text in a string, eg:
***
var my_object = { key_1: "some text", key_2: true, key_3: 5 };

var object_as_string = JSON.stringify(my_object);
// "{"key_1":"some text","key_2":true,"key_3":5}"

typeof(object_as_string);
// "string"
***
JSON.parse turns a string of JSON text into a JavaScript object, eg:
***
var object_as_string_as_object = JSON.parse(object_as_string);
// {key_1: "some text", key_2: true, key_3: 5}

typeof(object_as_string_as_object);
// "object"
***
3 years ago
try this
***
$json_string = 'domain.com/jsondata.json';
$jsondata = file_get_contents($json_string);
$obj = json_decode($jsondata,true);
echo "
";
print_r($obj);
***
3 years ago
To iterate over a multidimensional array, you can use RecursiveArrayIterator
***
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($json, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);

foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
echo "$key:\n";
} else {
echo "$key => $val\n";
}
}
***
Output:
***
John:
status => Wait
Jennifer:
status => Active
James:
status => Active
age => 56
count => 10
progress => 0.0029857
bad => 0
***
3 years ago
If you just need to check if there are ANY elements in the array
***
if (empty($playerlist)) {
// list is empty.
}
***
If you need to clean out empty values before checking (generally done to prevent explodeing weird strings):
***
foreach ($playerlist as $key => $value) {
if (empty($value)) {
unset($playerlist[$key]);
}
}
if (empty($playerlist)) {
//empty array
}
***
3 years ago
You could use a counter:
***
$i = 0;
$len = count($array);
foreach ($array as $item) {
if ($i == 0) {
// first
} else if ($i == $len - 1) {
// last
}
// …
$i++;
}
***
3 years ago