
An introduction to the Java for AnyLogic course.
We highlight the course objective, who will be presenting the course, who is the ideal student for this course as well as a brief course overview highlighting the key features we will be teaching.
The objective
In the Java for AnyLogic course, we will teach you how to make simpler, better models, faster in AnyLogic. We do this by making use of some simple and fundamental principles of Java the underlying programming language of AnyLogic.
At the end of this course, you will be using some the new skills you have learned to build more flexible and extensible models in AnyLogic. This will allow you to not only build more complex models but also allow you to do it much faster.
Who will be teaching you
Myself, Jaco-Ben Vosloo together with my co-instructor Vitor Lemos, will be taking you through the course step by step.
Together we have over 2 decades worth of experience in building models for major corporations and consultancies around the globe, in various industries, from mining and supply chains to project management and manufacturing.
I have also presented numerous AnyLogic training courses through the years from the AnyLogic Fundamentals course to custom training courses based on the specific client needs.
We have also been. privileged enough to present a number of projects at the AnyLogic and other conferences.
Although there are many courses and free content available on Java and how to become a better Java programmer this course was designed to specifically cater for AnyLogic users, applying all of the concepts learned to build simulation models.
The course structure
This course is structured in such a way that we cover theory, simple examples based on real-life problems, as well as assignments for most of the concepts we will be teaching.
We start our journey with some of the fundamental concepts in Java, to ensure we all start from the same base, variables, functions, the if statement and ternary operator, and for loops.
Then we move on to slightly more advanced stuff, Collections, While and do-while loops, and lastly switch .
After that, we switch gears to learn about some of the more interesting and advanced concepts in Java and how to use them in your simulation model. We start off with the heart of Java, Java classes, why they are crucial to building useful models and how to use them in AnyLogic.
Who should enroll
The ideal student for this course is existing AnyLogic users with some basic knowledge and experience building simulations models in AnyLogic and who want to improve their model building skills dramatically.
However, if you are an advanced user or have a Java programming background this might not be the course for you.
What next?
Feel free to take a look through the course description and some of the videos that are available as previews and we look forward to seeing you inside.
Some tips and tricks for getting the most value out of this course.
Please review this video in detail and take the advice seriously. This will ensure that you get the best value for money and more importantly, a significant return on the investment of your limited time and attention.
1) Don’t skip lectures
2) Participate as much as possible in the course
3) Practice the examples and create your own
4) Ask questions using the Q&A forum provided
This course is really a step-by-step guide to help you understand how you can use some fundamental Java principles in creating better, more flexible and scalable simulation models, much faster in AnyLogic.
An introduction to the basic concepts we will be covering in this section
We will be covering the following concepts.
Variables – What are they and how can you use them
Functions - or as they are known in Java “Methods”
The if-statement – How do you make things occur only under specific conditions
The ternary operator (The little brother of the if-statement)
The for loop – how do you make code execution iterative
What is an AnyLogic variable and how does it match its Java counterpart?
Aspects covered in this lecture:
What is a variable?
Creating Variables in AnyLogic
Naming of variables
AnyLogic Specific settings
Data types
Initial value
Access
Constant
Java docs or descriptions
Variables versus parameters
Variable types
Creating your own variables
At each section we will compare standard Java versus the setup in AnyLogic and use examples where applicable
How to use java functions, or methods as they are known in Java.
Aspects covered in this lecture:
What is a function?
Creating functions in AnyLogic
Naming of functions
AnyLogic Specific
Return type
Arguments
Function body
Access
Java docs or descriptions
Creating your own functions
Overloading
Behind the scenes
At each section we will compare standard Java versus the setup in AnyLogic and use examples where applicable
The most common, and essential, building blocks of any programming language... The If-Statement
An if statement is used to execute a block of code only if a specific condition is met.
A ternary operator is a special form of a single if statement
Aspects covered in this lecture:
The If Statement
Ternary operator
Some simple examples for each type
The student will learn how to repeat the same piece of logic by using a loop.
For loop is a special control statement that executes a block of code several times.
Preferred if the number of iterations is predefined or can be calculated
Aspects covered in this lecture:
For each based loops
Counter based loops
How to exit a loop prematurely
How to skip an iteration in a loop
Examples under each section
In this section we discuss Java objects that save a reference to multiple pieces of data in a structured format, also called collections.
We will be covering the following concepts.
Lists
ArrayList
LinkedList
Sets
HashSet
LinkedHashSet
TreeSet
Maps
HashMap
LinkedHashMap
TreeMap
There are examples where applicable
Learn how to efficiently store data in a more complex data structure.
Two main types of list we use:
LinkedList: fast for adding and deleting elements, but slow to access a specific element.
ArrayList: fast for accessing a specific element but can be slow to add to either end, and especially slow to delete in the middle
Aspects covered in this lecture:
ArrayLists
Sorting Lists
Create your own list in function
Some useful List functions
Examples under each section
Learn how to efficiently store unique data in a collection and how Set differs from Lists.
There are three main types of sets:
HashSet: no order of the items and future order might change
LinkedHashSet: An order based on the sequence of adding them
TreeSet: Order based on some characteristics of the objects in the set
The main difference to lists:
Can only contain one single reference to an object (No duplicates)
Sets have no index, you can't access the objects by index.
Very efficient in checking if an object exists within a set
Aspects covered in this lecture:
LinkedHashSet
Why we don’t use HashSet
Key benefits of Set
TreeSet
Sorting sets
Create your own set in function
Examples under each section
Lecture on how to properly store key/value pairs in a collection and how to use them efficiently in AnyLogic
Map is a unique collection of objects, stored as keys, but with corresponding values.
Two main types of maps we use in simulation models:
LinkedHashMap: keys are ordered based on the sequence of adding them
TreeMap: Keys are ordered based on some characteristics of the objects in the keyset
Similar to Sets there is an unordered version of Map, HashMap rarely used in simulation models since the order is not guaranteed.
Like Sets Maps have no index, you cant get the i’th element, but you can efficiently return a value for a given key
Aspects covered in this lecture:
LinkedHashMap
TreeMap
Looping through a map and other useful functions
Create your own map
Examples under each section
Why use a while loop when you have for loops? Learn why with this lecture.
Two loop types, While and Do While
Loops can be dangerous, if conditions are not set properly loops becomes infinite, causing your model to freeze
Aspects covered in this lecture:
while loop
do while loop
How to prematurely exit a loop
Examples under each section
A more user-friendly if statement. Learn how to take advantage of the switch statement.
Switch is a special conditional, control statement
Aspects covered in this lecture:
switch statement
Using switch with Option Lists (enumerators)
“if” vs “switch”
Examples under each section
Here we learn how to use a fundamental part of Object-Oriented Programming, classes. How to create classes and how do these compare to Agents in Anylogic
Aspects covered in this lecture:
Creating a Java Class in AnyLogic
Fields (Variables)
Constructors
Methods (Functions)
Converting a Java class into an Agent
Classes vs Agents
Examples under each section
How to make your models extendable by using class inheritance. What are the benefits and pitfalls?
Inheritance = where one object inherits all the properties of another
An important aspect of Object Orientated programming
Great for reusing code and sharing between multiple objects, allows for better organization and management of code
Aspects covered in this lecture:
Inheritance in AnyLogic
Inheritance in Java Class
Overriding a method
Polymorphism and casting
Examples under each section
Here the student learns about a special class, the Java Interface, and how it will improve the model development speed through the power of abstraction.
Interface = a set of abstract methods (methods without a body) and final or static variables
Aspects covered in this lecture:
Interfaces in AnyLogic
Default methods
Interfaces in Java Class
Polymorphism and casting
Examples under each section
In any simulation model, the ability to efficiently compare different objects/agents is a must. We often use this when prioritizing agents or within certain algorithms. This lecture teaches how to do this efficiently.
Objects in Java can be compared to each other through standard interfaces
Aspects covered in this lecture:
Implementing Comparable in agents
Creating a Comparator
Examples under each section
Learn about Java Enumerators, why they are important and how to use them in AnyLogic. Learn also some neat tricks to make your modeling experience more pleasant and bug-free.
Option List in AnyLogic = Enum Class in Java
List of a fixed set of constant values
Aspects covered in this lecture:
Why do we use predefined lists
Using option list
Using Enum class
Examples under each section
Use access levels modifiers to your and your team's advantage by better structuring your code.
Aspects covered in this lecture:
Example of access level
Why do we have multiple ways of checking if object A is the same as object B? When to use == or the method equals()?
Aspects covered in this lecture:
Example of testing different data types
Why String is such a special non-primitive type
This course is for beginner to moderate AnyLogic users that want to learn how to use the Java programming language and Object-Oriented Programming principles to make better more efficient models faster.
The course is structured from simple topics, like variables in Java, to more complex ideas such as Class Inheritance. You will start by learning the basics of Java, then we move to more complex features like data structures, and finish by learning and implementing complex concepts such as Inheritance, polymorphism and other Java features that allow extending AnyLogic's capabilities.
AnyLogic is a powerful tool and a market leader in the simulation world, but in order to build useful and efficient models, one needs to master Java and understand its capabilities. Mastering the most common and useful Object-Oriented programming concepts and applying them will result in better, faster and more extensible models. The ability to extend a simulation package via a powerful, and industry-standard, programming language is what differentiates AnyLogic from other offers in the market.
This course is the first part of a series aimed at providing a solid Java programing skillset to AnyLogic users, in order to solve complex problems by producing more robust, extendible and reliable models.