L01
所属分类:Java编程
开发工具:Java
文件大小:13KB
下载次数:2
上传日期:2012-04-01 02:42:51
上 传 者:
sakshi1234
说明: core java lecture from stanford university
文件列表:
Lecture 01 - Annotated\.classpath (232, 2009-01-06)
Lecture 01 - Annotated\.project (386, 2009-01-06)
Lecture 01 - Annotated\bin (0, 2011-09-26)
Lecture 01 - Annotated\bin\CallByValueChange.class (1015, 2011-09-26)
Lecture 01 - Annotated\bin\CallByValueExample.class (644, 2011-09-26)
Lecture 01 - Annotated\bin\CallByValueExample2.class (1038, 2011-09-26)
Lecture 01 - Annotated\bin\CopyingExamples.class (1032, 2011-09-26)
Lecture 01 - Annotated\bin\Hello.class (504, 2011-09-26)
Lecture 01 - Annotated\bin\MultiDimensionalExample.class (1281, 2011-09-26)
Lecture 01 - Annotated\bin\MyPoint.class (937, 2011-09-26)
Lecture 01 - Annotated\bin\StringComparison.class (992, 2011-09-26)
Lecture 01 - Annotated\bin\Student.class (1735, 2011-09-26)
Lecture 01 - Annotated\src (0, 2011-09-26)
Lecture 01 - Annotated\src\CallByValueChange.java (277, 2009-09-21)
Lecture 01 - Annotated\src\CallByValueExample.java (205, 2009-01-06)
Lecture 01 - Annotated\src\CallByValueExample2.java (283, 2009-01-06)
Lecture 01 - Annotated\src\CopyingExamples.java (404, 2010-01-05)
Lecture 01 - Annotated\src\Hello.java (108, 2010-01-05)
Lecture 01 - Annotated\src\MultiDimensionalExample.java (450, 2009-09-21)
Lecture 01 - Annotated\src\MyPoint.java (369, 2009-01-06)
Lecture 01 - Annotated\src\StringComparison.java (277, 2009-01-06)
Lecture 01 - Annotated\src\Student.java (4729, 2008-01-10)
Hello.java
-- this very simple program demonstrates some key principles of
programming regular (non-CS106) Java
- the function/method that will be executed first is:
public static void main(String[] args)
- to print information use:
System.out.println("Hello");
or
System.err.println("Hello");
I generally use System.out if what I'm printing represents the true
output of the program and System.err if I'm printing debugging information
or other status reports appropriate for administrators, but not for
most end-users
----
The following examples demonstrate Call by Reference vs. Call By Value
CallByValueExample.java -- in this example incrementing a parameter does nothing,
parameters are passed by value and so only the value of x is passed into the
method increment
CallByValueExample2.java -- in this case we are passing in an object, which is
a reference type. While we can't change what the parameter refers to, we can
change the values inside the object which is being referred to
CallByValueChange.java -- This example shows that we can't really change the object
itself to refer to a different object, this is what a true call-by-reference
would allow.
----
MyPoint.java -- this example provides several key points
- MyPoint includes a copy constructor, which can be used to create new
objects with the same values as an existing object.
- The equals method compares the values of an object rather than the object
itself. (We'll see a fancier, better version of equals once we've gone
over inheritance).
CopyingExamples.java
-- this illustrates the difference between creating a clone with MyPoint's copy
constructor vs. simply using assignment with =
----
StringComparison.java
- Two strings with the same character are not == but they are .equals.
Student.java
- this example illustrates a wide range of points, see the comments inside
the file for further information
MultiDimensionalExample.java
- this example (inspired by an official Sun example) shows how Java arrays
of arrays work. Notice the different arrays within cartoons have
different lengths.
近期下载者:
相关文件:
收藏者: