1 Java Basics for AnyLogic 6 Dang van son. 2 Agenda Development Environment Types & Expressions Calling Methods and Accessing Fields Replicated Objects.

Slides:



Advertisements
Similar presentations
2.1 Program Construction In Java
Advertisements

Arithmetic Calculations
Programming Languages and Paradigms The C Programming Language.
Types and Arithmetic Operators
Pemrograman Dasar - Data Types1 OPERATOR. Pemrograman Dasar - Data Types2 Arithmetic operator  + - * /  / operator denotes integer division if both.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
PHP Introduction.
1 Fundamental Data types Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions l Assignment statement l Increment.
Programming with Collections Collections in Java Using Arrays Week 9.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Data types and variables
Chapter 2 - Java Programming Fundamentals1 Chapter 2 Java Programming Fundamentals.
JavaScript, Third Edition
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
1 Data types, operations, and expressions Continued l Overview l Assignment statement l Increment and Decrement operators l Short hand operators l The.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Spreadsheets Objective 6.02
Python  By: Ben Blake, Andrew Dzambo, Paul Flanagan.
Introduction to Python Basics of the Language. Install Python Find the most recent distribution for your computer at:
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
1 Working with Data Types and Operators. 2 Using Variables and Constants The values stored in computer memory are called variables The values, or data,
Sahar Mosleh California State University San MarcosPage 1 A for loop can contain multiple initialization actions separated with commas Caution must be.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
Chapter 8: Collections: Arrays. 2 Objectives One-Dimensional Arrays Array Initialization The Arrays Class: Searching and Sorting Arrays as Arguments The.
C STRUCTURES. A FIRST C PROGRAM  #include  void main ( void )  { float height, width, area, wood_length ;  scanf ( "%f", &height ) ;  scanf ( "%f",
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
Mathematical Calculations in Java Mrs. G. Chapman.
Controlling Program Flow. Data Types and Variable Declarations Controlling Program Flow.
MT311 Java Application Development and Programming Languages Li Tak Sing( 李德成 )
Department of Electrical and Computer Engineering Introduction to C++: Primitive Data Types, Libraries and Operations By Hector M Lugo-Cordero August 27,
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
Mathematical Calculations in Java Mrs. C. Furman.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
Chapter Two Operators and Expressions Lesson Seven.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
PHP Programming with MySQL Slide 3-1 CHAPTER 3 Working with Data Types and Operators.
29 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Asserting Java © Rick Mercer Chapter 7 The Java Array Object.
© Rick Mercer Chapter 7 The Java Array Object.  Some variables store precisely one value: a double stores one floating-point number a double stores one.
Introduction to Python Developed by Dutch programmer Guido van Rossum Named after Monty Python Open source development project Simple, readable language.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
Arrays Chap. 9 Storing Collections of Values 1. Introductory Example Problem: Teachers need to be able to compute a variety of grading statistics for.
Chapter 7: Expressions and Assignment Statements
2.5 Another Java Application: Adding Integers
Chapter 7: Expressions and Assignment Statements
Assignment and Arithmetic expressions
Type Conversion, Constants, and the String Object
Operators and Expressions
Arithmetic Operator Operation Example + addition x + y
Examples of Primitive Values
Expressions and Assignment
Code Refresher Test #1 Topics:
Chapter 2: Java Fundamentals
Primitive Types and Expressions
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Java: Variables, Input and Arrays
OPERATORS in C Programming
Class code for pythonroom.com cchsp2cs
Review of Java Fundamentals
OPERATORS in C Programming
Presentation transcript:

1 Java Basics for AnyLogic 6 Dang van son

2 Agenda Development Environment Types & Expressions Calling Methods and Accessing Fields Replicated Objects Built-in Functions Main Language Constructs Example

3 Development Environment Development environment is Java and Eclipse based application Simulation applets run in any Java-enabled browser with the following version of JRE Simulation Application is pure Java applicationJava

4 Types & Expressions Primitive Types Double –represent real numbers: 1.43, 3.6E18, Int –represents integer numbers: 12, 16384, Boolean –represents Boolean (true/false) values Compound Types –Classes String –represents textual strings ArrayList, LinkedList –collections of objects HyperArray –represents multi-dimensional array in System Dynamics models …many others.

5 Types & Expressions Arithmetic operations Notation: +, –, *, /, %(remainder) In integer divisions, the fraction part is lost, e.g. 3 / 2 equals 1, and 2 / 3 equals 0 Multiplication operators have priority over addition operators The ‘+‘operator allows operands of type String Comparison operations Notation: >, >=, <, <=, ==, != Boolean operations Notation: &&(AND), ||(OR), !(NOT) Conditional operator Notation: condition ?value-if-true :value-if-false Assignments and shortcuts Notation: =, +=, -=, *=, /=, %=, ++, -- Example: a+=b is equivalent to a = a + b

6 Calling Methods and Accessing Fields Method call Type its name followed by parenthesis. If necessary, put parameters separated by commas within the parenthesis. Ex: x = time(); Accessing object fields and methods Use the model element name followed by dot ‘.’followed by the field/method name. Ex: statechart.fireEvent( “go”);

7 Replicated Objects Replicated objects are stored in a collection Items are indexed from 0 to N-1 Getting the current size of the collection: people.size() Obtaining i-thitem of the collection: people.get( i ) Adding a new object to the collection: add_people(); Removing an object from the collection: remove_people( person );

8 Built-in Functions System functions time(), getOwner(), pause(), isStateActive(…), etc Mathematical functions Basic: sqrt, sin, cos, tan, exp, log, round, zidz, xidz, etc– Array: add, sub, mul, sum, avg, min, max, get, etc Special functions Random numbers: uniform, exponential, bernoulli, beta, etc–Time related: delay, etc And more… See Utilities, Presentable, ActiveObjectand Agentclasses in AnyLogic Class Reference

9 Main Language Constructs Assignment / action statement: y = f(x1,x2) + 5*z; event.restart( uniform( 10, 20 ) ); Decision statement: if ( friendsRatio> attackConstant)attack(); else {escape();} Loop statement: double total = 0; for ( Person p : people ) total += p.income; for( inti=0; i<100; i++ ) send( msg, RANDOM );

10 Example

11

12