Lynda Java Essential Traning Notes
As I review, I would like to put some notes here as a reference, and a reminder that
I am, actually and necessarily making progress everyday.
- content
{:toc}
Using Primitive Data Types
instanceof
- If a STRING is not true, then it must be false.
toString
method (function, in fact)Double.parseDouble()
Exploring Syntax and Flow
break
is very important inswitch
statement. If you don’t add it at the end
of each case, it will keep running until the end ofswitch
statement.- The efficiency of loop does not matter so much with the format (for, foreach
while and do/while). But it does matter if your compiler is not efficient. - In JAVA, STRINGS are immutable. Aka, when you pass a string, you are just copying
its value to a new place, you CAN NOT change the ORIGINAL value. - A copy of the entire string is created when passed to a function.
StringBuilder
andindexOf
substring
trim
.- Some methods of
String
are very useful. And the more you put them into practice,
the better you can remember them. Practice makes perfect.
Working with Complex Objects
- Some useful Classes when deal with date values:
Date
GregorianCalendar
DateFormat
.
Exception Handling and Debugging
- Compile-time and run-time errors. Q: What are the differences between them?
- ArrayIndexOutOfBoundsException. (Very typical, do you know why?)
try...catch...
andtry...catch...finally...
It is often used in Java, most of the time
because you are not sure what will happen in the run time.
Using Data Collections
- Two dimension string.
- Resizable arrays with
ArrayList
. list.add
list.remove
.- You can manage unordered data with
HashMap
. It’s a CLASS. map.put
map.get(key)
.- Data in Hash Map is not in a particular order. So the only way is to use your key.
- Loop through collections using
Iterator
.listIterator.hasNext()
listIterator.next()
.
Creating Custom Classes
- Encapsulation: Packing of complex functionality to make it easy to use in an application.
- Refactor is really important in all kinds of programming.
- Organizing classes with packages.
getter
andsetter
methods in class fields definition.- Abstraction is essential for a good program. One “good” example is the Macro or
DEFINE
keyword in C and C++. In this lecture one example is,public static long final BLACK = 0x00000000
.
Working with Inheritence and Polymorphism
- Inheritence and Polymorphism are the TWO major features of Object-Oriented Programming.
- Inheritence: Parent/Child, Base/Derived, Superclass/Subclass. (they have the same meaning!)
- Inheritence:
extends
is used to create a subclass from superclass. - The details are hidden within the implementation.
this
keyword is very useful when you want to change something with super or subclass.- As an extremely common feature of Object-Oriented Programming, you can easily OVERRIDE
the functions (they call methods) from subclass to superclass. - Casting. One example:
Kalamata olive1 = (Kalamata)olives.get(0)
. Force the new object olive1 to be
Kalamata type. (Read more: why Typed Racket is necessary.) - Interface. More of less like superclass and subclass relationship. But it’s mostly for functions, I guess.
Yeah, it deals with ABSTRACTION. They give you the rough idea of what you should do, then you use
the superclass to fulfill the final functions. - Abstract class and methods.
abstract
ensures that functions of superclass are implemented.
“This method must be implemented!!!”.
Working with Files
File
InputStream
OutputStream
BufferedInputStream
- When dealing with files, beware to handle the exceptions.
FileUtils
from Apache Commons is helpful.- Parsing an XML file. Using Java Core library, or you can choose to use those
third-party libraries.
Preparing an Application for Deployment
- A JAR file is just a ZIP file. It is used to package your file for deployment.
Conclusion
This part of review is almost finished. Now let’s get down to How to Design Programs, and more
importantly, The Structure and Interpretation of Computer Programs, aka, SICP. This course is
still being taught in MIT, for first year CS students.