Java for Beginners University Greenwich Computing At School DASCO

Slides:



Advertisements
Similar presentations
What is shape function ? shape function is a function that will give the displacements inside an element if its displacement at all the node locations.
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
START DEFINITIONS values (3) N1 = (8, 1,-9) i N1 average N3,2 sum N2 = 0 temp N1 Do not guess or assume any values! Follow the values of the variables.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Lecture 05 - Arrays. Introduction useful and powerful aggregate data structure Arrays allow us to store arbitrary sized sequences of primitive values.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
An intro to programming The basic nitty-gritty that’ll make you scratch your head and say, “This is programming?”
Java for Beginners University Greenwich Computing At School DASCO
Java Basics. Java High-level language  More readable for humans  Need to be translated to machine language for execution Compilers  CPU-independent.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
Data Types and Operations On Data Objective To understand what data types are The need to study data types To differentiate between primitive types and.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CSCI 1226 FALL 2015 MIDTERM #1 REVIEWS.  Types of computers:  Personal computers  Embedded systems  Servers  Hardware:  I/O devices: mice, keyboards,
int num = 22; if (num > 0) if (num % 5 == 0) System.out.println(num); else System.out.println(num + “ is negative”);
A: A: double “4” A: “34” 4.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Programming in Java (COP 2250) Lecture 12 & 13 Chengyong Yang Fall, 2005.
CS100Lecture 21 Announcements For homework due Thursday, work alone -- do not work in pairs New class location: Olin 155 Office hour oops! Lyn: MW, 11:15-12:15.
CPSC 233 Tutorial January 21 st /22 nd, Linux Commands.
Java for Beginners University Greenwich Computing At School DASCO
1 Sections 3.1 – 3.2a Basic Syntax and Semantics Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 2 Basic Computation
Java for Beginners University Greenwich Computing At School DASCO
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Java for Beginners Level 6 University Greenwich Computing At School
Agenda Warmup AP Exam Review: Litvin A2
Java for Beginners University Greenwich Computing At School DASCO
[Array, Array, Array, Array]
Java for Beginners.
Computer Science 3 Hobart College
Some problems for your consideration
SELECTION STATEMENTS (1)
IDENTIFIERS CSC 111.
Building Java Programs Chapter 2
Java for Beginners University Greenwich Computing At School DASCO
Java for Beginners University Greenwich Computing At School DASCO
Outline Altering flow of control Boolean expressions
Java for Teachers Intermediate
Computers & Programming Languages
An Introduction to Java – Part I, language basics
SELECTION STATEMENTS (2)
Chapter 2: Java Fundamentals
Java Basics.
[Array, Array, Array, Array]
Chapter 2 Programming Basics.
Java for Beginners University Greenwich Computing At School DASCO
Understand the interaction between computer hardware and software
Introduction to Primitives
Introduction to Primitives
Other types of variables
Variables Here we go.
Introduction to Programming
Unit 3: Variables in Java
Java: Variables, Input and Arrays
Data Types and Maths Programming Guides.
Week 7 - Monday CS 121.
Presentation transcript:

Java for Beginners University Greenwich Computing At School DASCO Chris Coetzee

What do you learn last time? Wordle.org

3 Laws of Java Every line ends with a ; unless the next symbol is a { Every { has a } Classes start with capital letters, methods and variables start with lower case letters

Java’s structure Java programs are called ‘classes’ They exist inside a container called a project All classes have at least one method called main() Project: CheeseCake Class: CheeseCake Method: main() We write our ‘code’ here

Java class example Class name Main method

Levels of Java coding 1: Syntax, laws, variables, output 2: Input, calculations, String manipulation 3: Selection (IF-ELSE) 4: Iteration/Loops (FOR/WHILE) 5: Complex algorithms 6: Arrays 7: File management 8: Methods 9: Objects and classes 10: Graphical user interface elements

Variables vs. Value A variable is like a box What is inside the box can change or ‘vary’ The ‘thing’ inside the box is the value

5 types of variables double boolean int char String

Why not have just 1 type? Only type big enough to cope with sentences is Strings Strings are BIG compared with booleans/ints To save space, we only use the box type that is “just big enough” to contain the value we want. Less waste = faster programs!

Strings: “cat” “DA1 2HW” double boolean int char String

int: 23 0 -98 39290 -321 double boolean int char String

double: 1.2 -5.93 3.3333 double boolean int char String

boolean: true / false double boolean int char String

char: ‘a’ ‘3’ ‘@’ ‘A’ ‘ ’ double boolean int char String

What data type is each of the following? double -9 4.5 chicken false % £ 2.90 The cat is hungry now. 192.168.1.190 boolean int char String

Declare vs. Instantiate int number; number = 3; int number = 3; Instantiate All in one!

Strings String name; name = “Joe”; String name = “Joe”; Declare Instantiate All in one!

char char letter; letter = ‘a’; char letter = ‘a’; Declare Instantiate All in one!

double double price; price = 2.99; double price = 2.99; Declare Instantiate All in one!

boolean boolean fit; fit = true; boolean fit = true; Declare Instantiate All in one!

Be careful! true vs “true” “a” vs ‘a’ “4” vs 4 “2.99” vs 2.99 Note! Strings cannot do calculations

What does this do? int num; num = 23; System.out.println(23); System.out.println(num); System.out.println(“23”); Output 23

Combining values and variables int num1 = 5; int num2 = 10; System.out.println(num1+num2); System.out.println(num1+” + ”+num2); Output 15 5 + 10

What went wrong?! String number = “2”; int zombie = 4; System.out.println(number+number); System.out.println(zombie+zombie); Output 22 8