
Note: This class has hundreds of lines of source code, and hundreds of lines of comments - just download and open in your IDE!
We - the course instructors - start with introductions. We are a husband-wife team, studied at Stanford, and spent several years working in top tech companies, including Google, Flipkart and Microsoft.
Next, we talk about the target audience for this course: folks who are completely new to programming - liberal arts majors, accountants, lawyers, doctors - as well as engineers who have done some programming (maybe in Python, C# or C++) and are now looking to learn Java from 0 to 1.
By the end of this class, you will be able a fairly serious Java programmer, at an early intermediate level. You will understand object-oriented concepts, concurrency and threading, language features such as reflection, annotations and so on. You will also build a substantial UI app using Swing, and learn about the MVC paradigm.
If you are absolutely new to coding, don't be intimidated in the least - its just like cooking.
If coding is like cooking, functions are like food processors. They automate repetitive tasks by mechanically taking stuff in and churning stuff out.
Let's make sure you are all set up to run Java and write Java programs. We will walk through installing Java, and getting set up with IntelliJ, an excellent IDE
There are two important types of variables in Java: primitive types and object reference types. Oh, and there is also a special value called null.
Let's write our first little Java program. We will create a few variables and print some stuff to screen.
Ever wondered what's the biggest difference between Excel, and a serious programming language like Java? Loops. Loops are big productivity boosters. Lists and arrays are both ordered collections of elements. Arrays and lists not exactly the same though - in general lists are more handy to use.
Let's do some stuff using arrays, lists and loops. This is the basic idea of most imperative programming - create lists, and do stuff to those lists using loops.
Maps are also called Dictionaries, and that other name best describes what they are: collections of key-value pairs that you can look up blazingly fast.
Let's make sure we know how to use maps and do stuff with them: the idea of storing key-value pairs in a collection, and looking up the values for a particular key is key (bad pun alert!)
We introduce Java and summarize how it is an evolutionary descendent of C and C++. Memory management in Java, different programming paradigms and a quick how-to on the Intellij IDEA (the Java Integrated Development Environment we will be using)
Before we start with the serious stuff, remember this - Objects, like puppies, are your best friends.
Object-oriented programming languages require you to think in terms of objects and classes. We formally introduce these concepts, as well as encapsulation, abstraction, inheritance and other basic tenets of OO programming. Next come instantiation, member variables and member functions (static and non-static), start with access modifiers (public, private, protected) and finish with constructors and finalizers.
Static member variables and static member functions are class-specific, not object-specific.
Member variables and functions can be marked public, private or protected - these keywords are called access modifiers, and they govern the access that derived class objects have to their corresponding base class objects.
A simple coding drill that demonstrates all that we've covered so far: defining classes,instantiation(creating objects), different member variables and different member functions, getters, setters, constructors and finalizers.
We continue our simple coding drill that demonstrates all that we've covered so far: defining classes,instantiation(creating objects), different member variables and different member functions, getters, setters, constructors and finalizers. In this bit, we focus on instantiating objects, and on static member data.
What does it really mean for a class to derive from another class? We examine the idea of inheritance using Shapes.
We continue with our exploration of inheritance and explore how derived class objects have a full version of the base class object within them. This is illustrated using a class hierarchy involving planes and fighter planes.
Runtime polymorphism is an important OO concept. If an object of type Rectangle holds a reference to derived class Square, will our shape behave like a Rectangle or a Square?
We explore the Object base class, which all Java reference types derive from.
We introduce Interfaces: a special type of classes that have only function signatures but no function implementations.
Abstract base classes and abstract functions are covered in this class. We also compare when it makes sense to use interfaces, and when abstract base classes are a better choice.
Upcasting, downcasting and the instanceof operator. Upcasting is OK but be careful with downcasting!
Interface default methods are a new feature in Java, that allow us to go back and retro-fit new methods into old interfaces. Interface default methods involve adding implementations to interfaces, which might seem like cheating, but its all in a great cause: this prevents an explosion of the class hierarchy and maintains backward compatibility in code.
We've talked a lot about interfaces, now let's walk the talk with a nice little drill.
Stuff happens - that's life. And when stuff happens, exceptions get thrown. Let's understand how modern programming languages (including Java) deal with unexpected situations. The basic idea: a chain of responsibility, where somebody needs to stand up and be counted. Coding is a lot like life.
When are two objects 'equal'? How are the == operator and .equals() different from each other?
Generics are a language feature that help Java maintain its tight rules on Type Safety, while also facilitating code re-use.
Decades ago, when Java first appeared, its incredibly handy collections were among its biggest attractions over C++; much has changed, but Java collections are still incredible. Lists, maps, sets, and standard ways to iterate over them.
We tie together the ideas of collections and generics - a cool feature that came to Java relatively late (after C++ and C#) but is so handy!
Map elements can be ordered too! Java provides a special class called the TreeMap which is a Map in every sense of the word, and offers a way to order the keys stored in the Map, not something other Maps provide.
Java has a clever way to sort collections: using Comparator objects. (Aside: This clever technique combines the Strategy and the Command Design Pattern). We see how Comparators and Collections work together: nested classes (the classes inside classes) and types of nested classes (static and non-static classes which are also called anonymous inner or local classes).
We wrap up our exploration of inner classes with a look at Anonymous and local classes. Anonymous classes are used heavily in UI, while local classes are very infrequently used.
Working with files can sometimes seem boring - filled with repetitive boilerplate code. But files can get a bit more interesting if we get why they are so handy and so ubiquitous.
We will be making a useful Java application in this drill using concept of files and classes. The Java application will download daily stock data from a stock exchange website and output an excel file of top movers and heavily traded stocks. The ability to create Excel spreadsheets is a big win: we will use the Apache POI library, which will also serve to show we can use code written by someone else packaged into something called a JAR file.
We will be making a useful Java application in this drill using concept of files and classes. The Java application will download daily stock data from a stock exchange website and output an excel file of top movers and heavily traded stocks. The ability to create Excel spreadsheets is a big win: we will use the Apache POI library, which will also serve to show we can use code written by someone else packaged into something called a JAR file.
We will be making a useful Java application in this drill using concept of files, classes, nested classes and comparator. The Java application will download daily stock data from a stock exchange website and output an excel file of top movers and heavily traded stocks.
We will be making a useful Java application in this drill using a java library (JAR) called POI created by open-source powerhouse called Apache. The JAR POI has a set of classes to work with excel. The Java application will download daily stock data from a stock exchange website and output an excel file of top movers and heavily traded stocks.
We will be making a useful Java application in this drill using a java library (JAR) called POI created by open-source powerhouse called Apache. The JAR POI has a set of classes to work with excel. The Java application will download daily stock data from a stock exchange website and output an excel file of top movers and heavily traded stocks.
As computers have become multi-core, and then as cloud computing has taken off, the importance of threading has increased substantially. This lecture is an introduction to the concept of threading which allows programmers to do different things simultaneously. We will also discuss the differences between processes and threads, old school concepts vs new school concepts in threads and some use-cases of threads.
We'll talk about a specific use case for threading where spinning off multiple threads can give us huge performance gains. Java support for threading is great even in its traditional form. New libraries however, make working with threads far easier.
We study threading the way it has traditionally been done in Java - the Runnable interface; extending the Thread class; join(), sleep() and thread interrupts.
Multi-threading involves concurrent execution of threads, and this gives rise to an entire range of potential issues: thread interference, memory consistency and thread contention.
Methods can be marked as synchronized - we study the nuances of doing so. We also examine threading issues such as livelock, deadlock and starvation.
Let's figure out how to set up a multi-threaded program - and while doing so, we also encounter our first synchronization bug. We congratulate ourselves - wrestling with synchronization bugs is the badge of a serious programmer!
We continue with our drill, and use our first lock. We learn yet another important thread-related lesson - that static variables can not be locked using the synchronized keyword.
In this lecture, we will talk about new features of Java which significantly improves its support for concurrency - the Callable interface,executors,thread pools, lock objects, concurrent collections and atomic variables. We will show how these new features make multi-threading a lot more robust.
We go back and reprise our threading drill, but this time we do so using the new threading framework - Callables instead of Runnables, and Executors instead of the Thread objects, and Future objects to retrieve the results.
We now delve into the power of the new threading features - a CompletionService, for instance, which allows us to retrieve results from threads in the order in which they complete.
Functional, Imperative or Object-Oriented? Our choice of programming paradigm profoundly shapes how we design and write our code. We quickly explore how these three programming paradigms differ. This is a nice lead-in to lambda functions, which are a crossover hit from functional programming into object-oriented Java.
Introducing lambda functions, which are a functional programming concept that became so popular that Java added support for them. Very handy at reducing code bloat, particularly in UI programming.
More on Lambdas, and a look at aggregation operations - stream, map, filter, foreach - all of which are newly added to Java.
Recursive functions are functions that call themselves. This can be a little abstract to wrap your head around, but once you do, the idea is - beautiful.
Reflection and Type Introspection are ways to do things 'on-the-fly' with classes and objects: create objects directly from their classes, check out what methods these classes have, invoke those methods and so on. This lecture covers the pros, cons and complexities of reflection. We will also cover old school approach to unit testing and how reflection solves the problems of old school approach.
This lecture is about annotations. Annotations in Java are notes added to the code. The lectures explains how annotations are different from comments, how are they processed by compiler and how programmers can take advantage of annotations. We will also cover some built-in annotations.
Working with Date, Instant, Duration, Calendar and other common classes. Epoch time and what it means and how you use it in code to calculate time.
We will talk about packages and jars in this lecture. We will talk about what they mean, how they are useful and how jar files are smarter than zip files (Hint: self-awareness is the start of smartness. Another hint: Metadata)
We'll see how packages help create namespaces in Java. Packages are closely linked to the directory structure of Java source code.
A little drill where we see packages and jars in action
Objects can save themselves to file really easily in Java. - this used to be really hard, but now its pretty easy. We see how, and study the Serializable interface.
Objects have a way to clone themselves, but it is (surprisingly) rather broken in Java. We look at the Cloneable interface, and the .clone method. Not Java's finest hour.
Strings never change. Unlike almost everything else in life, they are immutable. Let's see how.
Frameworks are complicated sets of interconnected classes: they are incredibly powerful, but take some getting used to. This class introduces the concept of frameworks and explains how they work with a simple analogy. Using a framework has some trade offs, we give up complete control over our application in return for incredible speed of development and lots of built-in support.
Frameworks are heavily influenced by the Observer design pattern, communication is via events and the corresponding listeners.
This lecture is an intro to Swing - a Java framework used for building graphical user interfaces (GUI). We will cover basic components of Swing framework - JFrame and JComponent. We will also talk about its strengths and weaknesses.
The Model-View-Controller (MVC) paradigm is ubiquitious in UI programming; along with the Observer and Command patterns, MVC has practically defined modern User-Interface programming.
We plunge into Swing which is a prototypical UI programming framework. We start with the building blocks of Swing (JFrame and JComponent). Next - the idea of layouts which position controls on screen, and the border layout as an example. Then, JComponents(JTextArea, JTreeView, JMenuBar, JScrollPane, JPanel and JFileChooser).
This lesson explores the different classes that Swing provides for UI components such as menus (JMenuBar, JMenu, JMenuItem). Trees in Swing are pretty powerful but complicated to use, we learn how to deal with their intricacies.
We also learn how to capture and handle mouse events.
We build a serious Swing application - the News Curation App: The objective of the drill is to build an application that helps in curating news snippets and quickly summarizing articles. We will use helper classes to write to an HTML file, set up the Model portion of the MVC paradigm. This stores the underlying data for the application.
We continue with our News Curation Swing App. This class focuses on the View portion of the MVC paradigm. We will set up the UI of our drill in this video using JTree, JEditorPane and JTextArea. We learn the use of scrollpanes to set up scroll bars in our UI when content overflows its container.
As part of our News Curation Swing app - we setup a tree structure for navigation. In Swing this can be done using the JTree class which renders the view. The JTree requires a corresponding model and a bunch of listeners to set it up completely. This drill looks at wiring up the tree completely - no mean task!
We continue with our News Curation Swing App. This class focuses on the Controller portion of the MVC paradigm. We wire up a whole bunch of events listeners, for the File->Save menu, tree navigation and selection listeners, text area change listeners and the Go! button click listener.
We introduce JavaFX, a new framework which is intended to replace Swing as the standard GUI library for Java. JavaFX features are much more powerful than Swing - stuff such as Properties and Bindings, CSS support pack a real whammy.
Properties and Bindings are a Java beans programming construct which allow wiring up of variables to express relationships between them. JavaFX uses this extensively within its framework to expose granular updates for various events.
This class looks at code for defining, listening on and binding to a property. We'll introduce the ObservableValue<T> interface and see how it differs from the old Observer interface.
Two more problems and detailed solutions. Play the game of life where every cell can change states from live to dead based on its neighbours.
Then move on to breaking a document into chunks to send down to a client subject to very specific constraints.
A Java course for everyone - accessible yet serious, to take you from absolute beginner to an early intermediate level
Let’s parse that.
What's Covered:
Programming Drills (code-alongs, with source code included)