Learning a complex new language is no easy task especially when it s an object-oriented computer programming language like Java. You might think the problem is your brain. It seems to have a mind of its own, a mind that doesn't always want to take in the dry, technical stuff you're forced to study.
The fact is your brain craves novelty. It's constantly searching, scanning, wait...
Learning a complex new language is no easy task especially when it s an object-oriented computer programming language like Java. You might think the problem is your brain. It seems to have a mind of its own, a mind that doesn't always want to take in the dry, technical stuff you're forced to study.
The fact is your brain craves novelty. It's constantly searching, scanning, waiting for something unusual to happen. After all, that's the way it was built to help you stay alive. It takes all the routine, ordinary, dull stuff and filters it to the background so it won't interfere with your brain's real work--recording things that matter. How does your brain know what matters? It's like the creators of the Head First approach say, suppose you're out for a hike and a tiger jumps in front of you, what happens in your brain? Neurons fire. Emotions crank up. Chemicals surge.
That's how your brain knows.
And that's how your brain will learn Java. Head First Java combines puzzles, strong visuals, mysteries, and soul-searching interviews with famous Java objects to engage you in many different ways. It's fast, it's fun, and its effective. And, despite its playful appearance, Head First Java is serious stuff: a complete introduction to object-oriented programming and Java. You'll learn everything from the fundamentals to advanced topics, including threads, network sockets, and distributed programming with RMI. And the new. second edition focuses on Java 5.0, the latest version of the Java language and development platform. Because Java 5.0 is a major update to the platform, with deep, code-level changes, even more careful study and implementation is required. So learning the Head First way is more important than ever.
If you've read a Head First book, you know what to expect--a visually rich format designed for the way your brain works. If you haven't, you're in for a treat. You'll see why people say it's unlike any other Java book you've ever read.
By exploiting how your brain works, Head First Java compresses the time it takes to learn and retain--complex information. Its unique approach not only shows you what you need to know about Java syntax, it teaches you to think like a Java programmer. If you want to be bored, buy some other book. But if you want to understand Java, this book's for you.
作者简介
· · · · · ·
Kathy Sierra has been interested in learning theory since her days as a game developer (Virgin, MGM, Amblin'). More recently, she's been a master trainer for Sun Microsystems, teaching Sun's Java instructors how to teach the latest technologies to customers, and a lead developer of several Sun certification exams. Along with her partner Bert Bates, Kathy created the Head First ...
Kathy Sierra has been interested in learning theory since her days as a game developer (Virgin, MGM, Amblin'). More recently, she's been a master trainer for Sun Microsystems, teaching Sun's Java instructors how to teach the latest technologies to customers, and a lead developer of several Sun certification exams. Along with her partner Bert Bates, Kathy created the Head First series. She's also the original founder of the Software Development/Jolt Productivity Award-winning javaranch.com, the largest (and friendliest) all-volunteer Java community.
Bert Bates is a 20-year software developer, a Java instructor, and a co-developer of Sun's upcoming EJB exam (Sun Certified Business Component Developer). His background features a long stint in artificial intelligence, with clients like the Weather Channel, A&E Network, Rockwell, and Timken.
Head First (共14册),
这套丛书还有
《Head First JavaScript》,《Head First Java》,《Head First Agile》,《Head First Design Patterns》,《Head First HTML with CSS & XHTML》 等。
作为一本入门书,它是绝对出色的。一个星期就能让你明白怎么用Java写程序了。尤其是你有其它语言基础的情况下,这本书能迅速让你明白java的特质。 缺点是,它真的只是入门书。你必然还需要一本Java大字典,比如《Thinking in Java》,以便查阅Java在细节上的更多东西。关于这...
(展开)
Head First Java (2nd Edition),书的内容不错,讲解的浅显易懂、很有趣,比较适合初学者和巩固自己Java基础的读者。 如果想对Java做深入理解,推荐看《Java编程思想》或者 《Effective Java》,我目前在看《Effecitve Java》,不过看着挺吃力的。
(展开)
e就是exception类的一个对象。
当然啦,一个method可以throw很多的exception。你需要把它可能throw的异常都声明才可以,如果它们来自同一个父类,也可以只声明它们的父类。
当然啦,对应的catch也可以是很多个,但是它的顺序可是有讲究的。
Multiple catch blocks must be ordered from smallest to biggest.
就是从具体到一般,因为编译器是从上到下执行的。
如果你不想解决throw出来的问题,你也可以duck it.(我理解就是逃避它吧)
就是在调用throws exception的method的函数里,不用try-catch,而是继续throws exception。就好比推卸责任一样,层层上移,直到main()。
Handle or Declare 这是规矩。
如果你们都不管,最后让main()函数throw exception的话,JVM可能会崩溃哦!
刚才通过调试发现,如果执行try到最后有return语句的话,他会先去执行finally(),再回到return执行。没有的话,就直接返回了。
最后终于讲到了实际的例子。
我们需要四样东西:
Sequencer(CD机) & Sequence(CD) & Track(音轨MIDI Data) & MidiEvents(具体信息)
API Document里面的两句话:
sequencers play sequences, which contain tracks, which contain MIDI events.
A sequencer may provide controls that mute or solo individual tracks.
package chap06;
import javax.sound.midi.*;
public class MiniMiniMusicApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
//sequencers play sequences, which contain tracks, which contain MIDI events.
//A sequencer may provide controls that mute or solo individual tracks.
MiniMiniMusicApp mini=new MiniMiniMusicApp();
if(args.length<2){
System.out.println("Don't forget the instrument and note args");
}
else{
int instrument=Integer.parseInt(args[0]);
int note=Integer.parseInt(args[1]);
int result=mini.play(instrument,note);
System.out.println(result);
}
}
public int play(int instrument,int note){
try {
Sequencer player=MidiSystem.getSequencer();
player.open();
Sequence seq=new Sequence(Sequence.PPQ,4);
Track track=seq.createTrack();
ShortMessage first=new ShortMessage();
first.setMessage(192,1,instrument,0);
MidiEvent notefirst=new MidiEvent(first,1);
track.add(notefirst);
ShortMessage a=new ShortMessage();
a.setMessage(144,1,note,100);
MidiEvent noteon=new MidiEvent(a,1);
track.add(noteon);
ShortMessage b=new ShortMessage();
b.setMessage(128,1,note,100);
MidiEvent noteoff=new MidiEvent(b,16);
track.add(noteoff);
player.setSequence(seq);
player.start();
return 1;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
System.out.println("finally");
}
return 2;
}
}
public class Duck{
private int size;
public static void main(){
System.out.println("Size of duck is "+size);
}
}
这个是错的有木有啊!!!“size”是谁的size?
因为main函数也是static method啊!它定义在Duck类中啊!
还记不记得这句话:Static methods can't use non-static (instance) variables!
我已哭晕在厕所。。。
同样的:
Static methods can't use non-static methods!
public class Duck{
private int size;
public static void main(){
System.out.println("Size of duck is "+getSize() );
}
public int getSize()
{
return size;
}
}
这个也是错的啊啊啊!!!返回的“size”是谁的size?
还是这句话:Static methods can't use non-static methods!
别理我,我想静静。。。
而且通过我的亲身实践,好像即使non-static methods没有使用instance variables,compiler也是不让通过滴。
插一句话,用对象当然也能引用static methods,不过,这样真的好挫啊。
Static variables呐,一句话:one value per class,instead of one value peer instance.
而static variables只会在“类”第一次“载入”时初始化,它“住在”class中。
All instances of the same class share a single copy of the “static variables”.
那么问题来了,“类”什么时候载入呐?
JVM会在某人第一次试图建立一个属于该类的对象,或者使用该类的静态method或variable时“载入”这个“类”。
其中有两个关于静态初始化的保证:
1.static variables在属于该类的任何对象建立前初始化。
2.static variables在属于该类的任何静态方法运行前初始化。
——————————————————————————————————————
接下来,我们讲到了关键字final
Static final variables are constants.
例:
public static final double PI=3.1415926...
其中:
public: any code can access it.
static: you don't need an instance of class Math.
final: PI doesn't change.
有个规则要记住:常量的变量名要大写。(static final variables are constants)
这里static & final 缺一不可。(因为non-static variables也可以是final)
那final static variable怎么初始化呐?
这里有两种方法:
1.At the time you declare it.
public class Foo{
public static final int FOO_X=25;//注意命名规则
}
2.In a static initializer.
public class Foo{
public static final int FOO_X;//注意命名规则
static{
FOO_X=(double)Math.random();
}
}
记住哦,前面加上final就一定要用这两种方法初始化哦,不像单一个static有default。
static initializer里面的代码是在任何static method调用之前,甚至在任何static instance使用之前,就在“类载入”时运行。(before any other code can use the class)
final还可以用在non-static variables & methods & classes等等,分别是不能改变、不能重写(override)、不能继承。
final类中的方法无需声明为final methods.
然后就讲到了Math类的静态方法(其实都是静态的),感觉真的挺简单的。
接下来讲了wrapping a primitive 包装类
就相当于巧克力(primitive)外面包了一层锡箔纸(wrap)。
wrapping a value:
放入每一个重载的构造函数中。
注意:是super()!!!意味着如果父类有多个重载的构造函数,只有不含参数的那个构造函数被调用。
当然啦,我们也可以在super中传递参数去调用父类对应的重载构造函数。
天啦噜,父类构造函数一定要在子类构造函数前面完成,所以super()一定要写在第一行。
这时候,this关键字出现啦,this指的就是当前的对象。this只能出现在构造函数中,是当前对象的引用。this的作用呐就是在一个构造函数中去调用另一个重载的构造函数。因为this()也要出现在第一行,所以this()和super()一次只能出现一个啦。
也不能在构造函数里面用this()调用自己啦,那不就成递归了吗?
到目前为止,我们知道一个Object是怎么出生的了,那它的寿命呐?
请记住一句话:
An Object's life depends entirely on the life of references referring to it.
那么问题来了,引用变量的寿命怎么算?
这个决定于它是an instance variable or a local variable.(而不管它是primitive还是reference variable)
至于scope(作用域),哥哥都明白了呐~~~
还有三种情况使一个对象进入GC,只需记住:
An Object becomes eligible for GC when its last live reference disappers.
其他的就没有什么啦~只不过后面的五分钟小故事人家就看不懂了。。。
英语要加油了!!!
这本书说实话给我眼前一亮的感觉,大二学Java的时候,总感觉糊里糊涂的。有一些基本的概念掌握的也不是很清楚,读过之后顿时有脑洞大开的感觉。在这里把精彩的地方和大家分享一下。
1.Java是一种很简单的语言,而且应用面很广。String类有别于C语言里的string类,定义数组也稍有不同,比如int [] xxxx,在C语言里就是int xxxx [yyy]。(Java里数组能自动增长?哈哈应该不是吧)。
2. Java的结构呐,暂且用简单的三句话来总结:
i. Put a class in a source file.
ii. Put a method in a class.
iii.Put statements in a method.
总之就是Java的结构很紧密吧
3.一个工程至少有一个类,一个工程有且只有一个main函数!!!
4.boolean类型和integer类型可不兼容啊,比如
Overriding just means that a subclass redefines one of its inherited methods when it needs to change or extend the behavior of that method.
2014-10-01 21:59:40
Overriding just means that a subclass redefines one of its inherited methods when it needs to change or extend the behavior of that method.引自 class and objects
What's the differenc between a class and an objuct? A class is not an object. But it's used to construct them. A class is a blueprint for an object. It tells the virtuall machine how to make an object of that particular type. Each object from that class can have its own values for the instance variables of that class.
2014-10-01 22:03:24
What's the differenc between a class and an objuct?
A class is not an object. But it's used to construct them.
A class is a blueprint for an object. It tells the virtuall machine how to make an object of that particular type. Each object from that class can have its own values for the instance variables of that class.引自 classes and objects
e就是exception类的一个对象。
当然啦,一个method可以throw很多的exception。你需要把它可能throw的异常都声明才可以,如果它们来自同一个父类,也可以只声明它们的父类。
当然啦,对应的catch也可以是很多个,但是它的顺序可是有讲究的。
Multiple catch blocks must be ordered from smallest to biggest.
就是从具体到一般,因为编译器是从上到下执行的。
如果你不想解决throw出来的问题,你也可以duck it.(我理解就是逃避它吧)
就是在调用throws exception的method的函数里,不用try-catch,而是继续throws exception。就好比推卸责任一样,层层上移,直到main()。
Handle or Declare 这是规矩。
如果你们都不管,最后让main()函数throw exception的话,JVM可能会崩溃哦!
刚才通过调试发现,如果执行try到最后有return语句的话,他会先去执行finally(),再回到return执行。没有的话,就直接返回了。
最后终于讲到了实际的例子。
我们需要四样东西:
Sequencer(CD机) & Sequence(CD) & Track(音轨MIDI Data) & MidiEvents(具体信息)
API Document里面的两句话:
sequencers play sequences, which contain tracks, which contain MIDI events.
A sequencer may provide controls that mute or solo individual tracks.
package chap06;
import javax.sound.midi.*;
public class MiniMiniMusicApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
//sequencers play sequences, which contain tracks, which contain MIDI events.
//A sequencer may provide controls that mute or solo individual tracks.
MiniMiniMusicApp mini=new MiniMiniMusicApp();
if(args.length<2){
System.out.println("Don't forget the instrument and note args");
}
else{
int instrument=Integer.parseInt(args[0]);
int note=Integer.parseInt(args[1]);
int result=mini.play(instrument,note);
System.out.println(result);
}
}
public int play(int instrument,int note){
try {
Sequencer player=MidiSystem.getSequencer();
player.open();
Sequence seq=new Sequence(Sequence.PPQ,4);
Track track=seq.createTrack();
ShortMessage first=new ShortMessage();
first.setMessage(192,1,instrument,0);
MidiEvent notefirst=new MidiEvent(first,1);
track.add(notefirst);
ShortMessage a=new ShortMessage();
a.setMessage(144,1,note,100);
MidiEvent noteon=new MidiEvent(a,1);
track.add(noteon);
ShortMessage b=new ShortMessage();
b.setMessage(128,1,note,100);
MidiEvent noteoff=new MidiEvent(b,16);
track.add(noteoff);
player.setSequence(seq);
player.start();
return 1;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
System.out.println("finally");
}
return 2;
}
}
public class Duck{
private int size;
public static void main(){
System.out.println("Size of duck is "+size);
}
}
这个是错的有木有啊!!!“size”是谁的size?
因为main函数也是static method啊!它定义在Duck类中啊!
还记不记得这句话:Static methods can't use non-static (instance) variables!
我已哭晕在厕所。。。
同样的:
Static methods can't use non-static methods!
public class Duck{
private int size;
public static void main(){
System.out.println("Size of duck is "+getSize() );
}
public int getSize()
{
return size;
}
}
这个也是错的啊啊啊!!!返回的“size”是谁的size?
还是这句话:Static methods can't use non-static methods!
别理我,我想静静。。。
而且通过我的亲身实践,好像即使non-static methods没有使用instance variables,compiler也是不让通过滴。
插一句话,用对象当然也能引用static methods,不过,这样真的好挫啊。
Static variables呐,一句话:one value per class,instead of one value peer instance.
而static variables只会在“类”第一次“载入”时初始化,它“住在”class中。
All instances of the same class share a single copy of the “static variables”.
那么问题来了,“类”什么时候载入呐?
JVM会在某人第一次试图建立一个属于该类的对象,或者使用该类的静态method或variable时“载入”这个“类”。
其中有两个关于静态初始化的保证:
1.static variables在属于该类的任何对象建立前初始化。
2.static variables在属于该类的任何静态方法运行前初始化。
——————————————————————————————————————
接下来,我们讲到了关键字final
Static final variables are constants.
例:
public static final double PI=3.1415926...
其中:
public: any code can access it.
static: you don't need an instance of class Math.
final: PI doesn't change.
有个规则要记住:常量的变量名要大写。(static final variables are constants)
这里static & final 缺一不可。(因为non-static variables也可以是final)
那final static variable怎么初始化呐?
这里有两种方法:
1.At the time you declare it.
public class Foo{
public static final int FOO_X=25;//注意命名规则
}
2.In a static initializer.
public class Foo{
public static final int FOO_X;//注意命名规则
static{
FOO_X=(double)Math.random();
}
}
记住哦,前面加上final就一定要用这两种方法初始化哦,不像单一个static有default。
static initializer里面的代码是在任何static method调用之前,甚至在任何static instance使用之前,就在“类载入”时运行。(before any other code can use the class)
final还可以用在non-static variables & methods & classes等等,分别是不能改变、不能重写(override)、不能继承。
final类中的方法无需声明为final methods.
然后就讲到了Math类的静态方法(其实都是静态的),感觉真的挺简单的。
接下来讲了wrapping a primitive 包装类
就相当于巧克力(primitive)外面包了一层锡箔纸(wrap)。
wrapping a value:
放入每一个重载的构造函数中。
注意:是super()!!!意味着如果父类有多个重载的构造函数,只有不含参数的那个构造函数被调用。
当然啦,我们也可以在super中传递参数去调用父类对应的重载构造函数。
天啦噜,父类构造函数一定要在子类构造函数前面完成,所以super()一定要写在第一行。
这时候,this关键字出现啦,this指的就是当前的对象。this只能出现在构造函数中,是当前对象的引用。this的作用呐就是在一个构造函数中去调用另一个重载的构造函数。因为this()也要出现在第一行,所以this()和super()一次只能出现一个啦。
也不能在构造函数里面用this()调用自己啦,那不就成递归了吗?
到目前为止,我们知道一个Object是怎么出生的了,那它的寿命呐?
请记住一句话:
An Object's life depends entirely on the life of references referring to it.
那么问题来了,引用变量的寿命怎么算?
这个决定于它是an instance variable or a local variable.(而不管它是primitive还是reference variable)
至于scope(作用域),哥哥都明白了呐~~~
还有三种情况使一个对象进入GC,只需记住:
An Object becomes eligible for GC when its last live reference disappers.
其他的就没有什么啦~只不过后面的五分钟小故事人家就看不懂了。。。
英语要加油了!!!
0 有用 Orna§翺那 2006-04-14 02:50:37
That's easy but good!
0 有用 4fm 2011-12-06 23:06:52
这本是我在java方面唯一保留的书,该了解的都有了,再深的也不用掌握了,反正快被淘汰了
1 有用 远方一轮满月 2020-04-16 18:51:11
不喜欢这个风格的书,讲得太啰嗦了。
0 有用 木瓜守卫者 2010-03-23 05:06:50
超可爱的书,可我的java还是悲剧了
0 有用 軒轅鍾書 2011-02-08 15:03:59
熟悉:RMI JNLP,以及任意多的参数
0 有用 Pinkman 2022-04-18 15:47:20
我的CS第一课
0 有用 蜜桃少妇郭德纲 2022-03-20 19:08:50
谢谢,谢谢啊
0 有用 Neverland 2022-01-03 06:10:40
Best book to start Java…
0 有用 3点一直线 2021-07-25 06:42:53
很老的书,翻了一遍。 只适合没有任何背景的人入门。 这个只cover到 java 1.5, 不大好
0 有用 チーズ蒸しパン 2021-02-25 06:41:27
可能因为先会了别的编程语言,所以对大家说的”这本书深入浅出讲一些基本原理“没有特别的惊喜感吧,觉得不如去Jetbrains 一边看理论一边写题。。。