Computational Applications in Nuclear Astrophysics using Java Java course Lecture 2

Similar documents
COMP Primitive and Class Types. Yi Hong May 14, 2015

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Basics of Java Programming

Java enum, casts, and others (Select portions of Chapters 4 & 5)

CS313D: ADVANCED PROGRAMMING LANGUAGE

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

LECTURE 3 C++ Basics Part 2

Informatics Ingeniería en Electrónica y Automática Industrial

A flow chart is a graphical or symbolic representation of a process.

Chapter 3: Operators, Expressions and Type Conversion

JAVA OPERATORS GENERAL

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 4

Information Science 1

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Operators. Java operators are classified into three categories:

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

Operators. Lecture 3 COP 3014 Spring January 16, 2018

CIS 110: Introduction to Computer Programming

QUIZ: What value is stored in a after this

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 3

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

Visual C# Instructor s Manual Table of Contents

Darrell Bethea May 25, 2011

Chapter 2: Using Data

ISA 563 : Fundamentals of Systems Programming

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

SECTION II: LANGUAGE BASICS

Fundamental of C programming. - Ompal Singh

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

Chapter 6 Primitive types

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Operators & Expressions

Zheng-Liang Lu Java Programming 45 / 79

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

DEPARTMENT OF MATHS, MJ COLLEGE

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Lecture 3. More About C

Static Imports, Default Values, Number Types and More!

CS 106 Introduction to Computer Science I

CT 229. Java Syntax 26/09/2006 CT229

Full file at

4. Inputting data or messages to a function is called passing data to the function.

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Basic Operations jgrasp debugger Writing Programs & Checkstyle

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Declaration and Memory

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Java Basic Datatypees

Information Science 1

An Introduction to Processing

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

Fundamental of Programming (C)

COMP Introduction to Programming Primitive Types, Strings and Console I/O

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Chapter 2: Data and Expressions

3. Java - Language Constructs I

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

Language Fundamentals Summary

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Operators in C. Staff Incharge: S.Sasirekha

6.096 Introduction to C++ January (IAP) 2009

CSC 1214: Object-Oriented Programming

Variables, Data Types, and Arithmetic Expressions Learning Objectives:

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Programming in C++ 5. Integral data types

ECE 122 Engineering Problem Solving with Java

A variable is a name that represents a value. For

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Expressions and Precedence. Last updated 12/10/18

Getting started with Java

Chapter 2: Using Data

Topics Power tends to corrupt; absolute power corrupts absolutely. Computer Organization CS Data Representation

Work relative to other classes

Operators and Expressions

More Programming Constructs -- Introduction

Java Notes. 10th ICSE. Saravanan Ganesh

CMPT 125: Lecture 3 Data and Expressions

Fundamentals of Programming

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

JAVA Programming Fundamentals

Computers Programming Course 6. Iulian Năstac

Chapter 2: Data and Expressions

Variables and Operators 2/20/01 Lecture #

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

Operators in java Operator operands.

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Quick Reference Guide

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Chapter 2: Data and Expressions

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

COMP 110 Introduction to Programming. What did we discuss?

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Transcription:

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 2 Prepared for course 160410/411 Michael C. Kunkel m.kunkel@fz-juelich.de Materials taken from; docs.oracle.com Teach Yourself Java ISBN 9780078825705

Did you get this output? Homework Review

Homework Review

Java Data Types A data type specifies the type and size of values to be stored in an identifier. Java has 2 types of data type Reference data types (Non-Primitive data type) Primitive data types

Java Data Types Data Types Primitive Data Types char boolean integer floating point byte double int float long short Reference Data Types Arrays Classes Interfaces String etc. = Mostly used in this class

Java Primitive Data Types char data type is a 16-bit Unicode character ( u0000 to uffff ) : u0000 boolean data type can only have values "true" or "false" : false Not "0" or "1" like C ++ byte data type is a 8-bit integer (-128 to 127) : 0 short data type is a 16-bit integer ( 32768 to 32767) : 0 int data type is a 32-bit integer ( 2,147,483,648 to 2,147,483,647) : 0 long data type is a 64-bit integer (9,223,372,036,854,775,808 to 9,223,372,036,854,755,807) : 0L float data type is a 32-bit floating point (3.4e 038 to 3.4e+038) : 0.0f double data type is a 64-bit floating point (1.7e 308 to 1.7e+038) : 0.0d

Class Work Create a package in Eclipse Name it secondclass Create a public class named PrimitiveTypes Create a main method Using standard output, declare and print each type of primitive data type once. For the boolean case, try to set the value to a logical argument i.e. myboolean = (42>24)

Java Escape Sequences Escape sequences are used to signal an alternative interpretation of a series of characters. In Java, a character preceded by a backslash (\) is an escape sequence and has special meaning to the java compiler. Here are some example: \' print single quote \" print double quote \\ print a backslash \t print a tab \n print a new line

Class Work Using the package secondclass Create a public class named EscapeTypes Create a main method Using standard output, declare and print each kind of escape sequence once.

Java Escape Sequences

Class Work Using the package secondclass Create a public class name ReferenceTypes Create a main method Create another class named AType In AType declare an int, a double and a char In the main method Instantiate an object of Type. Set each primitive of AType to a value Using standard output and print each kind of escape sequence once.

Enum Type "An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must be equal to one of the values that have been predefined for it"

Enum Type Example

Class Work Using the package secondclass Create a public class name EnumTypes Create a main method Create an enum name IceCream Fill in the enum with at least 4 different ice creams In the main method Using standard output and print a sentence naming your least favourite ice cream from your enum.

When to Use What Data Type Why When How char We may need only a character value instead of using larger set of characters (Strings). We need to use only one character value. char mychar = 'a'; boolean Easy to use (can have only two values). Also has better memory usage values than some other types. We need to use simple flags that track true or false conditions. boolean mybool = true;

When to Use What Data Type Why When How byte Sometimes it can be better to use only a little part of memory than reserving/holding large parts for small processes. When memory savings actually matters. byte mybyte = 127; short Sometimes it can be better to use only a little part of memory than reserving/holding large parts for small processes. When memory savings actually matters. But when we need to use a little larger numbers. short myshort = 32767;

When to Use What Data Type Why When How int We may need to use numbers in our program. We need to represent 32-bit unsigned integer int myint = 1; long Sometimes int types can not hold larger values. We need to use larger numbers than the numbers provided by int. long mylong = 96543232934543L;

When to Use What Data Type Why When How float We may need to use numbers with decimal points. We need to use single precision 32-bit floating point numbers. float myfloat = 11.5F; double We may need to use numbers with decimal points. We need to use double precision 64-bit floating point numbers. double mydouble = 3.14; enum Enum constants cannot be changed after created. (Implicitly static and final) When you need to use predefined constant sets. enum Day {Sunday, Monday, Tuesday} Day.Monday

Predefined Java Classes Java has numerous built in classes to aide in programming in Java Some we have already used/mentioned String System One that we will use numerous times is the Math class

Class Work Using the package secondclass Create a public class name MathClassExamples Create a main method In the main method Using standard output and print at least 4 different math operations on any numeric data type. (Hint: Use Eclipse's content assist to see the different methods in the Math class)

Operators in Java As in most programming languages, operators are special symbols that perform specific operations Java has Assignment operators Logical operators Arithmetic operators Unary operators Relational and Equality operators Bitwise and Bitshift operator Comma operator Ternary operator = Homework = Will discuss today

Assignment Operators An assignment operator assigns the value on the right to the operand on the left example: int myint = 10; Operation on myint = 10 Assignment Value after Operation myint += 5 addition 15 myint -= 5 subtraction 10 myint *= 5 multiplication 50 myint /= 5 division 2 myint %= 5 modulus 0

Arithmetic Operators An arithmetic operator perform basic math operations example: int myint = 10; Operation on myint = 10 Arithmetic Value after Operation myint + 6 addition 16 myint - 6 subtraction 4 myint * 6 multiplication 60 myint / 6 division 1 myint % 6 remainder (remainder) 4

Logical Operators An logical operator returns a Boolean result that is based on the Boolean result of one or two other expressions Operation && Logic AND OR! NOT

Unary Operators The unary operators require only one operand; they perform various operations such as incrementing/ decrementing a value by one, negating an expression, or inverting the value of a boolean. Symbol Operator Description + Unary plus Indicates positive value - Unary Minus Negates an expression ++ Increment Increments a value by 1 -- Decrement Decrements a value by 1! Logical complement Inverts the value of a boolean

Relational and Equality Operators The equality and relational operators determine if one operand is greater than, less than, equal to, or not equal to another operand. Symbo Description "==" equal to (had to use "")!= not equal to > greater than >= greater than or equal to < less than <= less than or equal to

Comma Operators A comma operator is used to split up arguments within a functions' parameters.

Homework Teach yourself what Bitwise and Bitshift operators are Using the package secondclass Create a public class name SecondClassHomeworkYOURNAME Create a main method In the main method Using standard output Print at least 12 different operations using either arithmetic, logical, assignment, relational or equality. Demonstrate you can taught yourself what a ternary operator is Push your homework to GitHub

Homework Since the function of the lab is to Learn basic Java Reenforce lectures through programming The homework will be handed in electronically Via Github

Homework The homework will be graded as Does it run (boolean doesrun) Does it produce proper results (boolean iscorrect) Is it original (boolean isoriginal)

GitHub Please make sure you have git installed on your machine Most UNIX machines have it prepackage git --version Most Windows machines do not come prepackage with git I will be helping install this for those who need

GitHub Please go to https://github.com/ Make an account (its free) Got to https://github.com/mckunkel/bochumcourses Click to green link to "Clone or Download" Copy the link In a terminal make a directory where you want to put your Github repository type git clone LINKYOUCOPIED

Homework

Maven When ready to work on your homework Open Eclipse Click File->Import->Maven Project- >Existing Maven Project Click the check box for the pom file included Click Finish More on Maven in next lecture

Homework

Homework

GitHub When ready to submit your homework go to your Github folder go to the base directory with the homework is type git add * git commit -am "PUT A MESSAGE HERE" git push

Homework

Next Class More Java More on Maven Code examples from lecture 1 lecture 2