Course: Object-Oriented Compatibility

This course is one is a series on Java/Scala interoperability. These courses provide students the knowledge and techniques to work with combined Scala/Java code bases in all their forms.

  1. The first section of this course helps you install Scala tools, including a brief refresher on how to use the three most popular choices of programming tools: a text editor with SBT, Eclipse and IntelliJ IDEA. Pick the toolchain that you are most comfortable with, watch the videos of interest and follow along. Within minutes you will have all of the code examples provided in the course compiled and running. Most of the courses in the first section are shorter than the rest, with the exception of the IntelliJ IDEA video.
  2. The second section of this course shows you how Scala programs can work with Java code and data structures. This material is quite short, and is exactly what you would expect, with one notable exception, as you will see as you go through the course.
  3. The third section of this course shows you how to work with a Java dissembler and interpret what it shows you. After a quick review of Scala's object-oriented features, you will learn how to discover the proper incantations to call Scala code from Java, and to work with Scala data structures from Java.
  4. The fourth section of this course shows you how to access Scala objects and data from Java.
  5. The last section of this course offers guidance on how to write Scala code so it can be readily accessed from both Scala and Java.

Thank you for considering taking this course. I am sure you will enjoy this learning experience.

Date Lecture Changes
2013-11-04 Early access for this course ends
2013-06-01 Early access for this course begins

32 Lectures in 5 Sections, total video duration

JavaFromScala Section 1 Using Java Code and Data From Scala 3 lectures
JavaDataFromScala
Lecture 1-1
Accessing Java Data Structures from Scala 00:02:41

Non-final (mutable variables)

Static variables

Final variables (constants)

Introduction to Accessing Java Data Structures from Scala

JavaOOFromScala
Lecture 1-2
Accessing Java Classes and Interfaces from Scala 00:05:07

Class Instances

Interfaces

Inner Classes

Inner Static Classes

Collections

This lecture show how a Scala program can access Java classes and interfaces.

JavaVisibility
Lecture 1-3
Visibility (Public, Protected, Package-Private and Private) 00:02:39

Visibility (Public, Protected, Package-Private and Private)

SettingUp Section 2 Setting Up 2 lectures
toolInstall
Lecture 2-1
Installing First-Level Software Tools for this Course 00:14:21

Installing git

Installing Git On Mac
Installing Git on Windows
Installing Git on Ubuntu

Downloading Course Sample Projects

Installing Java Development Kit

JDK Settings

Installing sbt

Optional: Manual Installation of Scala

Installing an IDE

This is a short lecture that discusses the installation of the necessary software to start programming with Scala: git, Java development kit 6 or later, SBT and Scala. We also reveal the location of the downloadable sample code in this lecture, and how to get it.

Sbt
Lecture 2-2
Quick Review of SBT 00:05:55

Compiling Scala and Java

Compiling and Running the Project With SBT

Quick Review of SBT

javap Section 3 Your New Best Friend: javap, the Java Bytecode Disassembler 4 lectures
JavapIntro
Lecture 3-1
Introduction to javap 00:13:05

Decompiling a Java Interface

Decompiling a Java Class

You need high-level knowledge of what Scala code compiles to in order to access that code from Java. Depending on how the Scala instances were defined, some special incantations might be required for cross-language invocation. This lecture shows you how to start working with the JVM disassembler so you can discover this information for yourself.

quizJavapIntro
Lecture 3-2
Quiz: Javap Introduction 00:13:05

Quiz: Javap Classpath

Solution: Javap Classpath

Test your knowledge so far

JavapDecompilingJavaInner
Lecture 3-3
Decompiling Inner Java Classes 00:06:50

You need to know about decompiling inner Java classes because Scala creates so many of them.

JavapDecompilingJavaAnonymous
Lecture 3-4
Decompiling an Anonymous Java Class 00:03:53

Scala uses anonymous classes for closures, and closures are very common in Scala programs, so you should be familiar with how they are presented by javap. This information is quite easy to understand.

scalaFromJava Section 5 Working With Scala From Java 22 lectures
classSJ
Lecture 5-1
Scala Classes and Java

Working with Scala classes from Java

Visibility
Lecture 5-2
Scala Visibility From Java
public
protected[this]

Scala visibility from Java.

ClassSetterGetter
Lecture 5-3
Scala Setters and Getters 00:10:31

Scala Setters and Getters

Invoking From Java

This is a review of Scala class constructor arguments, setters and getters, followed by code examples showing how to invoke them from Java.

quizClassSetterGetter1
Lecture 5-4
Quiz 1 on Setters and Getters 00:02:47

Quiz: Setters and Getters 1

Solution: Setters and Getters 1

Test your knowledge of Scala setters and getters!

quizClassSetterGetter2
Lecture 5-5
Quiz 2 on Setters and Getters 00:02:01

Quiz: Setters and Getters 2

Solution: Setters and Getters 1

Test your knowledge of setters and getters!

BeanProperty
Lecture 5-6
@BeanProperty 00:06:33

Adding Java-style setters and getters to Scala objects.

quizBeanProperty
Lecture 5-7
Quiz on Bean Properties 00:01:51

Quiz: Bean Properties

Solution: Bean Properties

Test your knowledge!

ClassDefaultArgs
Lecture 5-8
Working With Default Arguments 00:04:20

Scala implements default arguments by emitting extra methods. This lecture shows how to recognize and use those methods.

ScalaObjects
Lecture 5-9
Working With Scala Objects from Java

Accessing Scala Objects from Java

Scala Objects Without Companion Classes
Scala Objects With Companion Classes

Extractors (Unapply)

Arity 1
Arity > 1

This lecture shows how to decompile Scala objects and work with them from Java.

quizClassObject
Lecture 5-10
Quiz on Classes vs. Objects

Quiz: Classes vs. Objects

Solution: Classes vs. Objects

Test your knowledge!

traitDecompile
Lecture 5-11
Decompiling Scala Traits 00:05:15

Pure Traits

Traits With An Implementation

Traits are unique to Scala and are not directly accessible from Java. However, they are implemented as a Java-compatible interface and perhaps a Java-compatible implementation class. We will examine the method signatures stored in those files in this lecture. In a later lecture we will see how to invoke the methods from Java.

TraitInterfaceDecompile
Lecture 5-12
Examining the Generated Interface for a Scala Trait 00:03:48

This short lecture examines the generated interface for a Scala trait in more detail.

traitsFromJava
Lecture 5-13
Accessing Scala Traits from Java 00:06:54

Accessing a Scala Trait from Java (Method 1)

Accessing a Scala Trait from Java (Method 2)

This lecture explores two techniques of accessing Scala traits from Java.

TraitImplDecompile
Lecture 5-14
Examining the Scala Trait Implementation 00:04:45

Decompile Multiple .class Files at Once

This lecture examines the Scala trait implementation in greater detail.

quizTraitClasses
Lecture 5-15
Quiz on Trait Classes 00:01:24

Quiz: Trait Classes

Solution: Trait Classes

Test your knowledge!

CaseClassConstruction
Lecture 5-16
Constructing Scala Case Classes 00:09:10

Constructing Case Classes From Java

A quick review of constructing Scala Case Classes from Scala, followed by an explanation of how to do the same thing from Java.

quizDecompilingScalaSoFar
Lecture 5-17
Quiz So Far on Decompiling Scala 00:01:51

Quiz: Javap So Far

Solution: Javap so Far

Test your knowledge!

StaticInitializer
Lecture 5-18
Insider's Look at the Static Initializer

Insider's Look at the Static Initializer

CaseClassJava
Lecture 5-19
Working With Scala Case Classes From Java

Accessing Case Class Companion Objects From Java

Accessing Case Class Companion Classes From Java

Working with Scala case classes from Java, including the companion object and companion class.

quizCaseClass1
Lecture 5-20
Quiz 1 on Case Classes 00:01:14

Quiz: Case Classes

Solution: Case Classes

Test your knowledge!

TuplesSJ
Lecture 5-21
Using Scala Tuples From Java 00:18:08

Other Methods of Tuples

Converting Tuples to Argument Lists

Java and Scala can both use tuples for many reasons, including passing multiple values together without creating a class, returning multiple value from a method, amongst other uses. This lecture describes how Java can work with tuples created by Scala code, how Java can create tuples, and how to use the many methods defined by and for tuples. The topic of using tuples as arguments lists is also introduced.

Lecture 5-22 Figuring Out Changing Scala Compiler Output Free! 00:17:21

Controlling SBT's Scala Compiler Version

Scala Case Class Differences between Scala 2.9.0 and 2.10

Each version of the Scala compiler emits slightly different code. This lecture shows how to discover changes between Scala compiler versions using a little-known SBT option and a bash script to make that process easier. A demonstration of the process is given that shows changes in case class code generation between Scala 2.9.0 and 2.10.

$249usd