Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!

Seb Mathe

Ranch Hand
+ Follow
since Sep 28, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Seb Mathe

Mi,

My company is writing a Java Web application and we're looking for an installer.

Today, all is done "by hand".

We need to :

- Install the JRE if not present
- Install an application server (Tomcat) if not present
- Connect to a DB Server (must be present) and create a DB
- Configure the application (db connection, log files,...) and deploy it.

In the future, we'll need to be able to deploy the application on multiple application servers (Websphere, JBoss, ...)

Does somebody know a product that can do all this work ?
13 years ago


you need to pass the scjp again or improve yourself to know that the static method can be called by both the class name and instance name.



Well, I'm happy to learn sothething today...
However, I'm not sure to get my SCJD exam if I call all my static methods from instance names...


A method that is declared static is called a class method. A class method is always invoked without reference to a particular object. An attempt to reference the current object using the keyword this or the keyword super in the body of a class method results in a compile-time error. It is a compile-time error for a static method to be declared abstract.

A method that is not declared static is called an instance method, and sometimes called a non-static method. An instance method is always invoked with respect to an object, which becomes the current object to which the keywords this and super refer during execution of the method body.




I think Jeff's example is not a good one :


Static method can be inherited
example below


public class Test1
{
public static void testMethod()
{
System.out.println("Testing");
}
}

public class Test2 extends Test1
{
public static void main(String[] args)
{
Test2 test2 = new Test2();
test2.testMethod();
}
}



because test2.testMethod() doesn't make sense.
It should be : Test2.testMethod()
But here, the argument list is the same (int i).

Error should be something like "duplicate method something(int)..."
I disagree...


will print false, false, true, and I dont't think that Sun's implementation of hashcode() for the Long class is inappropriate...
14 years ago
" false false true " is possible and Correct !

Part of the contract of hashcode() :

It is not required that if two objects are unequal according to the equals(java.lang.Object) method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hashtables.


It is sometimes impossible to produce different hashcodes for two different objects (regarding equals method).
Look at the Long object : Long L1 and Long L2 are equals if L1.longValue() == L2.longValue();
But there are 2^64 different possible values for a long, and hashcode() should produce an int...
14 years ago
x = 8 | 12 ^ 8
= 1000 | (1100 ^ 0100) (binary)
= 1000 | 0100
= 1100
= 12 (decimal)

y = 8 ^ 5 & 6
= 1000 ^ (0101 & 0110)
= 1000 ^ 0100
= 1100
= 12

Note that the operator precedence is &, ^,
If the first thread executes before the second one, ABABCD will be printed.
If the second thread executes before the first one, CDDCAB will be printed.
But a deadlock may occur :

1. Thread1 requires lock on s1 (synchronized(s1)) -> OK
2. Thread2 requires lock on s2 (synchronized(s2)) -> OK
3. Thread1 requires lock on s2 -> WAITING
4. Thread2 requires lock on s1 -> WAITING
DEADLOCK

well in that case we need to run the rmiregistry executable



No, we don't need it : have a look at LocateRegistry.createRegistry()

And have a look at

Javaranch names policy too
Integers in java are 32 bits signed integers.
So range is from -2^31 to 2^31-1

2^31-1 is the biggest positive int value, so in binary a zero (sign bit) folowed by 1 :
0111 1111 1111 1111 1111 1111 1111 1111 (binary)
7fffffff (hexa)

-2^31 is is the lowest negative int value, so in binary a 1 (sign bit) folowed by 0 :
1000 0000 0000 0000 0000 0000 0000 0000
80000000 (hexa)
I don't understand the question, can you clarify ?
14 years ago


If the class is declared public, then the default constructor is implicitly given the access modifier public ; if the class is declared protected, then the default constructor is implicitly given the access modifier protected ; if the class is declared private, then the default constructor is implicitly given the access modifier private ; otherwise, the default constructor has the default access implied by no access modifier.

Moreover, there are some objects that have no sense without a minimal set of parameters.

If there were always a default Constructor, we could imagine something like :

Color c = new Color();
// Which color does c represent ??

File f = new File();
// Ok, but what's the file name here ?

Integer i = new Integer();
// What's i value ?
14 years ago
From the java.lang.reflect package doc :


Provides classes and interfaces for obtaining reflective information about classes and objects. Reflection allows programmatic access to information about the fields, methods and constructors of loaded classes, and the use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions.

Yes, this behavior is normal...

Try using setLength(0) to truncate the file.
14 years ago