Course in Modern C++ for Java Programmers

Fundamental course in Modern C++, based on the new standard C++ 11/14/17, aimed at Java programmers

Java was desiged as a sort of simplified C++. It is easy to be led to believe they are similar because of the similarities in the syntax. Unfortunately there are many pitfalls to fall into for Java programmers, as many things look the same but works in fundamentally different ways.

This basic course is aimed at experienced Java programmers, whom as quickly as possible want to start programming i C++. We consistenty refer to Java and illustrate similarities and point out differences.

Of course we use modern C++, Which means C++17, a modern design perspective and frquently use of the standard library.

We can't resist to quote Bjarne Stroupstrup, the creator of the language when he speaks about this:

Within C++ is a smaller, simpler, safer language struggling to get out.

Where he put the focus on that

...code that is statically type safe, has no resource leaks, and catches many more programming logic errors than is common in code today. And it will run fast.
This is what you will learn
  • Understand how C++ differentiates to Java, such as pointers/references, copy/move constructors, destructors and more
  • Program in Modern C++
  • Effective usage of the standard library
  • Design user-defined data types
  • Understand and apply insights regarding memory management in C++
Course Contents

Background and Overview

A few words about the evolution of the language

  • Langauge evolution
  • The concept Modern C++
  • Syntax summary
  • Simple compilation
  • C++ reference

Similarities with Java

We start with simpler parts of the language where C++ and Java are rather similar.

  • Data types
  • Duck-typing in C++ or how to use auto
  • Expressions
  • Statements
  • Function declarations and function calls
  • Uses of namespaces, instead of packages and how it differs

Differences to Java

In this chapter we discuss how C++ strongly deviates from Java

  • Organization of compilation units
  • Data areas and life-cycles
  • Global data in the data area
  • Local data in the stack area
  • Dynamic data in the heap
  • How to act in the absence of a garbage-collector?
  • Include is not the same as import
  • Taking advantage of the pre-processor (CPP)
  • The merit of inlining
  • An executable JAR file, is not the same as a compiled C++ program. How do you build apps in C++?

Pointers and references

In this chapter we discuss the pointer concept in C/C++ and C++ references, both lvalue and rvalue dito

  • Pointer declarations
  • Dereferencing operator
  • Address operator
  • Pointer arithmetics
  • Dangling pointers
  • The illusion of arrays
  • Nativ text strings and the danger of using them
  • Pointers to struct/class objects
  • Function pointers
  • References
  • Call-by reference
  • Return by-reference
  • What is move semantics
  • Rvalue references

Lambda Expressions

With the introduction of lambda expressions, C++ have definitely entered the stage of modern and hip languages. We find it a little bit amusing that C++ beat Java with three years, introducing support for lambda expressions.

  • Lambda syntax
  • Passing free variables by reference or value
  • Functions taking lambdas as parameters and/or returning lambdas

Text Strings and Regexes

The majority of bugs in C/C++ programs has their root in wrong usage of text strings. Just by consequently use std::string instead, the code quality increases significantly. In this chapter we discuss how to use the string class and utilize regex for searching and substitution.

  • Why using std::string instead of nativ strings
  • Overview of std::string and its functions/operators
  • What is SSO (Short String Optimization) and how it is used
  • Working with legacy strings
  • Character oriented functions
  • Multi-line string literals
  • What is a regex
  • The regex support in modern C++
  • Matching text data to patterns
  • Searching using patterns
  • Replacing text fragments using patterns
  • Using regex iterators
  • Typical use cases
  • Splitting and joining strings

I/O Streams and Files

In this chapter we discuss how to apply formatted I/O with the console, files, and buffers.

  • ostream / ofstream / ostringStream
  • istream / ifstream / istringstream
  • Bi-directional I/O with fstream
  • Manipulators
  • The input idiom
  • Line-oriented input
  • Word-oriented input
  • Character-oriented input

Helper Types

Discssion of helper classes and function you need to know about

  • Pair
  • Tuple
  • Date-times
  • Durations
  • Clocks
  • Date formatting
  • Random number generators

Container Types

Discussion of the STL container types

  • Sequence containers and typical methods
  • vector / dequeue / array
  • list / forward_list
  • Associative containers
  • Tree vs. hash implementations
  • Unique vs. multi-key versions
  • set / unordered_set
  • map / unordered_map
  • Container adapters

Iterators and Intervals

Discussion of the STL iterator concept

  • What is an iterator
  • What is a range and how is it used
  • Iterator categories
  • I/O iterators
  • End-point adapter functions

STL Algorithms

Discussion of STL algorithms

  • What is a std::* algorithm
  • The STL architecture
  • How to pass the business logic into algorithm functions
  • Understanding *_n and *_if suffixes of functions
  • Using functions with predicates
  • Using back_insereter iterators
  • Transforming and aggregating
  • Sorting
  • Populating data inot containers

Classes (User Defined Types)

How to define user-defined types, aka classes

  • What is a user-defined type
  • Specification vs. implementation
  • Member variables and functions
  • Object creation (instantitation)
  • Visibility
  • Constructors
  • Destructor
  • Inline member functions
  • Member overloading
  • The pointer 'this'

Class Member Forms

Discussion of all variants of class member forms

  • Class variables and functions
  • Member references
  • Read-only variables
  • Const marked functions
  • Inner classes and they differ to ditto in Java
  • Friend declarations

Constructors and Destructors

All you need to know about constructors and destructors

  • Initialization
  • Default constructor
  • Destructor
  • Copy constructor
  • Assignment operator
  • Pitfalls
  • Standardized class form
  • Enforcing compiler-generated members
  • Deleting compiler-generated members
  • Type conversion constructor
  • Type conversion operator
  • What is move semantics
  • Move constructor
  • Move assinment operator

Heap Allocated Objects

How to create and maintain dynamically allocated memory blocks

  • What is dynamic memory anyway
  • Using the new and delete operators
  • Pitfalls
  • The placement variant of new

Exceptions

How to deal with exceptions

  • What is an exception
  • Throwing exceptions
  • Catching exceptions
  • The merrits of automatic destructions during throw
  • Exceptions in the standard library
  • Pitfalls

Templates

C++ is primarly a template meta-programming langauge. In this chapter we tell you more.

  • What is a template
  • Function templates
  • Class Templates
  • Member function templates
  • Template parameter forms
  • Type eqiuvalence
  • Template specialization
  • Pitfalls
  • Type traits
  • Using decltype()
  • Variadic templates

Operator Overloading

User-defined operator overloading is the key to DSL (Domain Specific Language).

  • What is operator overloading
  • Syntax
  • Overloadable operators
  • Rule set
  • Overloading of arithemtic operators
  • Overloading of relational operators
  • Overloading of I/O operators
  • Overloading of ++/-- operators
  • Overloading of the index operator
  • Overloading of the arrow operator
  • Overloading of the function-call operator

Inheritance and Virtual Functions

Here we discuss class hierachies, inheritance and virtual functions

  • Why do I inherit in C++, but extend in Java
  • Syntax
  • Protected visibility
  • There is no such thing as package visibility in C++
  • Invocation of super-class members
  • References and pointers of root class type
  • Performing down-casts using dynamic_cast
  • Constructor initialization order
  • Base class visibility
  • Virtual member functions and why they are important
  • What is the key difference between virtual methods and non-virtual methods in C++ and how do they compare to Java
  • How do I make a class and/or method abstract in C++
  • Use of override and final specifiers
  • Multiple inheritance and why you need to be careful
  • Implementing Java-style interfaces in C++

The Pre-Processor

How to use the C pre-processorm; when to use and when not to

  • Include files
  • CPP constants
  • Pre-defined constants
  • Conditional compilation
  • Include guards
  • CPP macro functions
  • Stringification and name catenation
  • Assertions

Building C++ Applications

Brief discussion about how to compile and build C++ applications

  • Compilation steps
  • What is an abstract syntax tree (AST)
  • The assembler
  • Inline assembly code
  • The linker
  • Name mangling of C++ names
  • Inspecting the linker symbol table
  • The loader
  • Tracing executions
  • Compiler flags for warnings
  • Compiler flags for optimizations
  • Compiler flags for debugging
  • Creating a static archive file
  • Creating a dynamic linked library

Build Tools and Open-Source Libraries

Overview of some build tools and open-source libraries

  • Make
  • GNU Autotools
  • Premake
  • CMake
  • Gradle
  • Doxygen
  • Google Test
  • log4cxx
  • Boost

Standards and Guidelines

The C++ standardization process

  • Tracking the standard
  • Tracking compilers and what they support
  • Online compilers
  • The big C++ conference (cppcon)
  • The C++ Core Guidelines
  • GSL - The Guidelines Support Library
Facts
NameModern C++ for Java Programmers
Duration4 Days
Level Beginner
AudienceExperienced Java developers
Prerequisites Working knowledge and experience of Java programming
Tools
  • GCC/G++ compiler, version 8 or later
  • Jetbrains CLion IDE
  • Ubuntu Linux @ VirtualBox or WLS @ Windows-10
On-Site Course

If you order an On-Site course, we will come to you and hold the course in your office. The price is determined by our price model and is based on the number of course days, number of participants and any travel and lodging.

Read more about out price modell and term of sales here.

Related Courses
CourseDays Level
C++ Supplementary3IntermediateShow
Unit Testing in C++ with Google Test1IntermediateShow
Threads Programming using Modern C++3 AdvancedShow
Linux Systems Programming using Modern C++3AdvancedShow
C++ 11/14/17 for C++ Programmers3IntermediateShow