Vladimir Scheglov

Greenhorn
+ Follow
since Jun 19, 2006
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 Vladimir Scheglov

In my opinion:

Case 1:
0 - because null is not object
Case2:
1 - only empty string ""
Case3:
3 - empty string, s1 from empty string, s2 from empty string
Case 4:
1 - only "Testing"

All string literals creates only once and locating in string pool
May Deadlock or not, if yes - where?
class Sub extends Super
{
void method(Sub sb1) //oveloading, no overriding
{
System.out.println("Sub");
}
}


Sub sb1 = new Sub();
Super spb = new Sub();

spb.method(sb1); //spb is Super and Super dont know about overloading method in Sub

If you need overriding


class Sub extends Super
{
void method(Super sb1)
{
System.out.println("Sub");
}
}
ALSO

protected class InnerOne {
static double methoda() { return d1; }
}

Non-static inner class cannot have static declarations
float f1 = Float.floatValue(s); //non-static method floatValue
float f2 = Float.valueOf(s); //right only for J2SE 5.0
float f3 = new Float(3.14f).floatValue(); //right
float f4 = Float.parseFloat(1.23f); //for parseFloat need String
float f5 = Float.valueOf(s).floatValue(); //right
float f6 = (float) Double.parseDouble("3.14");//right
You will see NullPointerException, because aray initialize default values. For objects (String is object) default value is null
This example will print only Not
When i change a and b=100 it only show "Yes"

Integer class with value from -128 to 127 in Java pools

Integer i1 = -128;
Integer i2 = -128;
i1==i2 - true, because i1 and i2 from pool

Integer i1 = -129;
Integer i2 = -129;
i1==i2 - false

Integer i1 = 127;
Integer i2 = 127;
i1==i2 - true, because i1 and i2 from pool

Integer i1 = 128;
Integer i2 = 128;
i1==i2 - false


But

Integer i1 = new Integer(127);
Integer i2 = new Integer(127);
i1==i2 - false, because i1 and i2 create at Runtime, not from pool
Hi Joshua
But why this code compile fine?

if (false){
int i = 5;
}
Interesting
This code not compile

while (false){
int i = 5;
}
local variable "test" must be final
When you using while (++i < args.length) first value of i in boolean expression after ++ is 1. When you start program with one argument (like java c arg), program no output. When you start program with two arguments (like java c arg1 arg2), program output without last argument.

Correct code:
class c {
public static void main(String[] args) {
int i = 0;
while (i++ < args.length) {
System.out.print(args[i]);
}}}
int i = 3/3*6/2*6-1;

* and / - have same priority

3/3 = 1
than
(3/3)*6 = 6
than
((3/3)*6)/2 = 3
than
(((3/3)*6)/2)*6 = 18
than
((((3/3)*6)/2)*6) - 1 = 17
more better code:
class Outer {
String str = "Hello";

class Inner {
Outer outer = Outer.this;

public void println(){}
}
}

public class Test{

public static void main(String arg[]){
Outer.Inner inner = new Outer().new Inner() {
public void println(){
System.out.println(outer.str);
}
};
inner.println();
}
}
A. (i == l) //compiler error, compare objects of different class
B. (i == d) //compiler error, compare objects of different class
C. (d == l) //compiler error, compare objects of different class
D. (i.equals (d)) //false, compare objects of different class
E. (d.equals (i)) //false, compare objects of different class
F. (i.equals (42)) //true, 42 autoboxing to Integer and then compare contents
G. (i.equals (l)) //false, compare objects of different class
H. (l.equals (d)) //false, compare objects of different class

Method equals() for Wrapper classes always return false if compared objects diffrents class
P.S Sorry for bad English
This code will compile. In your code mySubClass and myOuterClass are inner for mySuperClass, but non-static inner class couldn't have static method
line 01: class mySuperClass
line 02: {
line 03: mySuperClass()
line 04: {
line 05: }
line 06: }

line 07: class mySubClass extends mySuperClass
line 08: {
line 09: }
line 10:
line 11: class myOuterClass
line 12: {
line 13: public static void main (String args[])
line 14: {
line 15: new mySubClass();
line 16: }
line 17: }