z*y
2 楼
class testString
{
public static void main(String args[])
{
String s = "1234567";
System.out.println(s.charAt(0));
System.out.println(s.charAt(1));
System.out.println(s.length());
System.out.println(s.substring(0, s.length()-1));
}
}
输出:
1
2
7
123456
string index 如果是从0开始的,那么最后应该输出整个串,right?
{
public static void main(String args[])
{
String s = "1234567";
System.out.println(s.charAt(0));
System.out.println(s.charAt(1));
System.out.println(s.length());
System.out.println(s.substring(0, s.length()-1));
}
}
输出:
1
2
7
123456
string index 如果是从0开始的,那么最后应该输出整个串,right?
t*5
3 楼
I got an offer from Boeing as a Level 3 engineer. Could any "qianbei" talk
about their experiences in Boeing?
Thanks in advance!
about their experiences in Boeing?
Thanks in advance!
m*6
4 楼
hi
d*e
6 楼
really? nice, good job, I hope I could get a job from them
what will you be doing?
what will you be doing?
M*0
7 楼
Java所有API含有“从a到b”的a都是inclusive b都是exclusive
j*a
9 楼
:~$ javac -version
javac 1.6.0_32
:~$ cat a.java
import java.lang.Integer;
class a {
public static void main(String args[]) {
int a=1000, b=1000;
System.out.println(a==b);
Integer c=1000, d=1000;
System.out.println(c==d);
Integer e=100, f=100;
System.out.println(e==f);
}
}
:~$ javac a.java
:~$ java -version
java version "1.6.0_32"
Java(TM) SE Runtime Environment (build 1.6.0_32-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.7-b02, mixed mode)
:~$ java a
true
false
true
:~$
【在 z*y 的大作中提到】
: class testString
: {
: public static void main(String args[])
: {
: String s = "1234567";
: System.out.println(s.charAt(0));
: System.out.println(s.charAt(1));
: System.out.println(s.length());
: System.out.println(s.substring(0, s.length()-1));
: }
javac 1.6.0_32
:~$ cat a.java
import java.lang.Integer;
class a {
public static void main(String args[]) {
int a=1000, b=1000;
System.out.println(a==b);
Integer c=1000, d=1000;
System.out.println(c==d);
Integer e=100, f=100;
System.out.println(e==f);
}
}
:~$ javac a.java
:~$ java -version
java version "1.6.0_32"
Java(TM) SE Runtime Environment (build 1.6.0_32-b05)
Java HotSpot(TM) 64-Bit Server VM (build 20.7-b02, mixed mode)
:~$ java a
true
false
true
:~$
【在 z*y 的大作中提到】
: class testString
: {
: public static void main(String args[])
: {
: String s = "1234567";
: System.out.println(s.charAt(0));
: System.out.println(s.charAt(1));
: System.out.println(s.length());
: System.out.println(s.substring(0, s.length()-1));
: }
h*c
10 楼
It looks like a severe bug. but
1. java doesn't have operator overload etc.
to compare value of ADT, non-built-in, the interface function is equal().
a.equal(b).
2. probaly == compare the references' hash values, it happens to be a
collision? not sure about 2.
Above all Java is not c++.
【在 j*a 的大作中提到】
: :~$ javac -version
: javac 1.6.0_32
: :~$ cat a.java
: import java.lang.Integer;
: class a {
: public static void main(String args[]) {
: int a=1000, b=1000;
: System.out.println(a==b);
: Integer c=1000, d=1000;
: System.out.println(c==d);
1. java doesn't have operator overload etc.
to compare value of ADT, non-built-in, the interface function is equal().
a.equal(b).
2. probaly == compare the references' hash values, it happens to be a
collision? not sure about 2.
Above all Java is not c++.
【在 j*a 的大作中提到】
: :~$ javac -version
: javac 1.6.0_32
: :~$ cat a.java
: import java.lang.Integer;
: class a {
: public static void main(String args[]) {
: int a=1000, b=1000;
: System.out.println(a==b);
: Integer c=1000, d=1000;
: System.out.println(c==d);
r*l
11 楼
You need to understand the differences between "==" and "equals()".
"c == d" means that is c and d are same objects. "c.equals(d)" tells you if
their values are the same. With equals(), you always get consistency.
Internally, Java maintains a small Integer cache from -127 to 127. When you
do autoboxing, if the value is within that range, the objects from the cache
is returned. e and f are both from the cache and they are the same object.
For c and d, > 127, when Java does boxing, it creates new object using new
Integer(). That's why c and d are not the same object.
【在 j*a 的大作中提到】
: :~$ javac -version
: javac 1.6.0_32
: :~$ cat a.java
: import java.lang.Integer;
: class a {
: public static void main(String args[]) {
: int a=1000, b=1000;
: System.out.println(a==b);
: Integer c=1000, d=1000;
: System.out.println(c==d);
"c == d" means that is c and d are same objects. "c.equals(d)" tells you if
their values are the same. With equals(), you always get consistency.
Internally, Java maintains a small Integer cache from -127 to 127. When you
do autoboxing, if the value is within that range, the objects from the cache
is returned. e and f are both from the cache and they are the same object.
For c and d, > 127, when Java does boxing, it creates new object using new
Integer(). That's why c and d are not the same object.
【在 j*a 的大作中提到】
: :~$ javac -version
: javac 1.6.0_32
: :~$ cat a.java
: import java.lang.Integer;
: class a {
: public static void main(String args[]) {
: int a=1000, b=1000;
: System.out.println(a==b);
: Integer c=1000, d=1000;
: System.out.println(c==d);
r*l
12 楼
This is not a bug. Nothing is in conflict with Java SE or JVM specs.
This is related to auto boxing and unboxing in Java. You are right to say
Java does not have operator overload.
"==" does NOT compare hash values.
You are right to say Java is not c++.
I see that probably you are a very good c++ programmer.
【在 h**********c 的大作中提到】
: It looks like a severe bug. but
: 1. java doesn't have operator overload etc.
: to compare value of ADT, non-built-in, the interface function is equal().
: a.equal(b).
: 2. probaly == compare the references' hash values, it happens to be a
: collision? not sure about 2.
: Above all Java is not c++.
This is related to auto boxing and unboxing in Java. You are right to say
Java does not have operator overload.
"==" does NOT compare hash values.
You are right to say Java is not c++.
I see that probably you are a very good c++ programmer.
【在 h**********c 的大作中提到】
: It looks like a severe bug. but
: 1. java doesn't have operator overload etc.
: to compare value of ADT, non-built-in, the interface function is equal().
: a.equal(b).
: 2. probaly == compare the references' hash values, it happens to be a
: collision? not sure about 2.
: Above all Java is not c++.
h*c
13 楼
Where did you get these things?
API?
【在 r*****l 的大作中提到】
: This is not a bug. Nothing is in conflict with Java SE or JVM specs.
: This is related to auto boxing and unboxing in Java. You are right to say
: Java does not have operator overload.
: "==" does NOT compare hash values.
: You are right to say Java is not c++.
: I see that probably you are a very good c++ programmer.
API?
【在 r*****l 的大作中提到】
: This is not a bug. Nothing is in conflict with Java SE or JVM specs.
: This is related to auto boxing and unboxing in Java. You are right to say
: Java does not have operator overload.
: "==" does NOT compare hash values.
: You are right to say Java is not c++.
: I see that probably you are a very good c++ programmer.
k*y
15 楼
I think you only have references to the objects in Java. So in some sense
the object variables are just like pointers in C.
So "==" means they have the same address. Should use "equals" to compare the
dereference values.
【在 h**********c 的大作中提到】
: It looks like a severe bug. but
: 1. java doesn't have operator overload etc.
: to compare value of ADT, non-built-in, the interface function is equal().
: a.equal(b).
: 2. probaly == compare the references' hash values, it happens to be a
: collision? not sure about 2.
: Above all Java is not c++.
the object variables are just like pointers in C.
So "==" means they have the same address. Should use "equals" to compare the
dereference values.
【在 h**********c 的大作中提到】
: It looks like a severe bug. but
: 1. java doesn't have operator overload etc.
: to compare value of ADT, non-built-in, the interface function is equal().
: a.equal(b).
: 2. probaly == compare the references' hash values, it happens to be a
: collision? not sure about 2.
: Above all Java is not c++.
h*c
16 楼
So my question is:
So when you println an object. suppose you didn't override toString,
is that value printed an absolute address or hashed value of an address?
the
【在 k*****y 的大作中提到】
: I think you only have references to the objects in Java. So in some sense
: the object variables are just like pointers in C.
: So "==" means they have the same address. Should use "equals" to compare the
: dereference values.
So when you println an object. suppose you didn't override toString,
is that value printed an absolute address or hashed value of an address?
the
【在 k*****y 的大作中提到】
: I think you only have references to the objects in Java. So in some sense
: the object variables are just like pointers in C.
: So "==" means they have the same address. Should use "equals" to compare the
: dereference values.
k*y
17 楼
The address is already unique and fits in 32bit/64bit, so I don't see why
the implementation need to hash it again. But I don't think it matters,
since Java doesn't have the concept of address and what do you want to do
with that?
I am new to Java too. Please correct me if I am wrong.
【在 h**********c 的大作中提到】
: So my question is:
: So when you println an object. suppose you didn't override toString,
: is that value printed an absolute address or hashed value of an address?
:
: the
the implementation need to hash it again. But I don't think it matters,
since Java doesn't have the concept of address and what do you want to do
with that?
I am new to Java too. Please correct me if I am wrong.
【在 h**********c 的大作中提到】
: So my question is:
: So when you println an object. suppose you didn't override toString,
: is that value printed an absolute address or hashed value of an address?
:
: the
j*a
18 楼
i see. thank you.
if
you
cache
【在 r*****l 的大作中提到】
: You need to understand the differences between "==" and "equals()".
: "c == d" means that is c and d are same objects. "c.equals(d)" tells you if
: their values are the same. With equals(), you always get consistency.
: Internally, Java maintains a small Integer cache from -127 to 127. When you
: do autoboxing, if the value is within that range, the objects from the cache
: is returned. e and f are both from the cache and they are the same object.
: For c and d, > 127, when Java does boxing, it creates new object using new
: Integer(). That's why c and d are not the same object.
if
you
cache
【在 r*****l 的大作中提到】
: You need to understand the differences between "==" and "equals()".
: "c == d" means that is c and d are same objects. "c.equals(d)" tells you if
: their values are the same. With equals(), you always get consistency.
: Internally, Java maintains a small Integer cache from -127 to 127. When you
: do autoboxing, if the value is within that range, the objects from the cache
: is returned. e and f are both from the cache and they are the same object.
: For c and d, > 127, when Java does boxing, it creates new object using new
: Integer(). That's why c and d are not the same object.
f*n
19 楼
See the documentation for Object.toString()
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#
this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
It is whatever number hashCode() returns. If you overrode hashCode(), it
will return the number that method returns.
If you didn't override hashCode(), then see the documentation for Object.
hashCode()
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#
As much as is reasonably practical, the hashCode method defined by class
Object does return distinct integers for distinct objects. (This is
typically implemented by converting the internal address of the object into
an integer, but this implementation technique is not required by the JavaTM
programming language.)
So it is some kind of unique identifier; it may or may not be based on the
address.
【在 h**********c 的大作中提到】
: So my question is:
: So when you println an object. suppose you didn't override toString,
: is that value printed an absolute address or hashed value of an address?
:
: the
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#
this method returns a string equal to the value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
It is whatever number hashCode() returns. If you overrode hashCode(), it
will return the number that method returns.
If you didn't override hashCode(), then see the documentation for Object.
hashCode()
http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#
As much as is reasonably practical, the hashCode method defined by class
Object does return distinct integers for distinct objects. (This is
typically implemented by converting the internal address of the object into
an integer, but this implementation technique is not required by the JavaTM
programming language.)
So it is some kind of unique identifier; it may or may not be based on the
address.
【在 h**********c 的大作中提到】
: So my question is:
: So when you println an object. suppose you didn't override toString,
: is that value printed an absolute address or hashed value of an address?
:
: the
f*n
20 楼
No
1. It is not a bug. This is the correct behavior
2. == on references ALWAYS compares if the two references point to the same
object. It has nothing to do with "hash values" or anything like that
【在 h**********c 的大作中提到】
: It looks like a severe bug. but
: 1. java doesn't have operator overload etc.
: to compare value of ADT, non-built-in, the interface function is equal().
: a.equal(b).
: 2. probaly == compare the references' hash values, it happens to be a
: collision? not sure about 2.
: Above all Java is not c++.
1. It is not a bug. This is the correct behavior
2. == on references ALWAYS compares if the two references point to the same
object. It has nothing to do with "hash values" or anything like that
【在 h**********c 的大作中提到】
: It looks like a severe bug. but
: 1. java doesn't have operator overload etc.
: to compare value of ADT, non-built-in, the interface function is equal().
: a.equal(b).
: 2. probaly == compare the references' hash values, it happens to be a
: collision? not sure about 2.
: Above all Java is not c++.
g*g
21 楼
Simply put, as long as it's an object (Integer included), you are
not supposed to use == for comparison, unless you want to check
it's the reference.
Even e == f yields true, it's a bad usage.
【在 r*****l 的大作中提到】
: This is not a bug. Nothing is in conflict with Java SE or JVM specs.
: This is related to auto boxing and unboxing in Java. You are right to say
: Java does not have operator overload.
: "==" does NOT compare hash values.
: You are right to say Java is not c++.
: I see that probably you are a very good c++ programmer.
not supposed to use == for comparison, unless you want to check
it's the reference.
Even e == f yields true, it's a bad usage.
【在 r*****l 的大作中提到】
: This is not a bug. Nothing is in conflict with Java SE or JVM specs.
: This is related to auto boxing and unboxing in Java. You are right to say
: Java does not have operator overload.
: "==" does NOT compare hash values.
: You are right to say Java is not c++.
: I see that probably you are a very good c++ programmer.
s*h
22 楼
不应该 -1 的呀
java里面的范围一般都是(start, end+1)
java里面的范围一般都是(start, end+1)
相关阅读
航天员5天只擦身不洗澡 与地面医生“密语”通话 女儿为聂海胜唱起生日歌 英雄感动当场落泪Where can I find word report?神六座椅靠衬垫调整 价值相当于同等重量黄金 (转载)东方时事解读 激光武器由于起点相同中国的技术似乎更胜一筹神五/六是第几代集体订的规划?神六12日上午发射 中国全面向航天大国挺进凤凰连线:美国航天局关注神六发射情况 以央视为首的神六报道泄密严重 为日后欧印日载人航天省钱神舟六号主着陆场四次演习全部结束 快讯:今日下午4时左右神六变轨火箭专家:神七将携三航天员飞天 运载神八火箭样机已制出中国正在启动女航天员选拔北京航天飞控中心宣布:飞船正常入轨 主伞打开就已经算成功了.为“神六”欢呼的中国人尽管欢呼!华盛顿的智囊应该好好思考思考神舟六号的发射和回收都在内蒙古境内(图)迎接神六返回 (转载)航天日志:神舟六号航天员的第三天快讯:飞船进行第16圈飞行 将飞越北京