Datalogi A 1: 8/9. Book: Cay Horstmann: Big Java or Java Consepts.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Lecture 1: Comments, Variables, Assignment. Definitions The formal (human-readable) instructions that we give to the computer is called source code The.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Today’s topics: I/O (Input/Output). Scribbler Inputs & Outputs  What are the Scribbler’s inputs and outputs?  reset button  motors/wheel  light sensor.
CMT Programming Software Applications
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
Some basic I/O.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
Hello, world! Dissect HelloWorld.java Compile it Run it.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
CSE 131 Computer Science 1 Module 1: (basics of Java)
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
INTRODUCTION TO JAVA CHAPTER 1 1. WHAT IS JAVA ? Java is a programming language and computing platform first released by Sun Microsystems in The.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
CSE 131 Computer Science 1 Module 1: (basics of Java)
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 15: More-Advanced Concepts.
Chapter 2: Java Fundamentals
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Programming Fundamentals 2: Simple/ F II Objectives – –give some simple examples of Java applications and one applet 2. Simple Java.
Copyright 2008 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Copyright 2010 by Pearson Education 1 Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading:
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 3 – Introduction to C# Programming Outline 3.1 Introduction 3.2 Simple Program: Printing a Line.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
© 2007 Lawrenceville Press Slide 1 Chapter 4 Review Assignment Statement An assignment statement gives a value to a variable. Assignment can take several.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
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.
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Object Oriented Programming Lecture 2: BallWorld.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Lecture 4 – Scanner & Style
CompSci 230 S Programming Techniques
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
Chapter 2 More on Math More on Input
Chapter 1: Introduction to computers and C++ Programming
Introduction to Computer Science / Procedural – 67130
Introduction to.
Variables, Expressions, and IO
Getting Started with C.
Computer Programming Methodology Introduction to Java
Lecture Note Set 1 Thursday 12-May-05
An Introduction to Java – Part I, language basics
Building Java Programs
MSIS 655 Advanced Business Applications Programming
Chapter 3 – Introduction to C# Programming
COM-152: Computer Programming Types, Variables, Operators Part 1 of 2
F II 2. Simple Java Programs Objectives
Computer Programming-1 CSC 111
Chapter 2: Java Fundamentals cont’d
Presentation transcript:

Datalogi A 1: 8/9

Book: Cay Horstmann: Big Java or Java Consepts

Cay Horstmann: Java Essentials If you have an earlier edition – then use it. buy it from students who have attended the course earlier

Aim: Basics of programming –Central constructs in programming languages –variables, expressions, statements –if, while, for,… –subroutines (procedures, functions) –lists, arrays, classes, objects Basics of writing interactive systems –Windows, panels, fields –Events from mouse, keyboard, buttons, etc.

Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor, libraries. A bit about software engineering – methods used in constructing programs. A bit about graphics

Windows, frames, buttons, menus

Computer Science A What you have to do 3 * home work 3 * mini-project 1 * oral test based on mini-projects All information available on

Java programs public class Hello{ public static void main(String args[]){ System.out.println(”Hello world”); } A program contains classes (here Hello )chapters classes contains methods (here main )paragraphs methods contains statements (here System.out… ) One class has the same name as the file ( Hello.java ) One method in that class is called main

Java programs Extra spaces and newlines does not matter, except: No newlines in text strings ( ”… ” ) At least one space between words public static Use indentations to make programs readable. The compiler ignores it, but I don’t Case does matter String, class Hello and Hello.java

Comments You can write comments in a program. Comments are ignored by the compiler. Line comments: int i=6; // declare a variable Block comments: /* The main entry point in the program: */ public static void main(String args[]){

Java statements Print out System.out.println( …. Reading input … Declare variables int counter; Change values of variables counter = 1; this can be combined into int counter = 1; Method calls if statements while statements

Expressions and values For now: strings and numbers String name=”Hello”; int counter = 2; (case does matter) Operations + on strings to concatenate +,-, *,/ on numbers add, subtract, multiply, divide

Types String var1 = ”1”; // text strings char var2= ’1’; // single characters int var3 = 1; // integers double var4 = 1.0; // real values Everything can be converted to String – but it doesn’t work the other way. Int can be used as double, but not the other way. Division between two integer values is an integer. If one or both are reals then the result is a real. String to integer conversion: Integer.parseInt(stringVariable);

Assignment int counter; create a variable called counter counter=1; store the value 1 in the variable counter=counter+1; compute the value of the expression counter+1 and store that in the variable. counter now has the value 2

Input/output Input/output via command prompt screen Input/output via Dialog windows Input/output via window system (mouse/graphics etc.) Input/output via files We will wait a bit with the last two ways of reading a writing

Input/output Input/output via command prompt screen java.util.Scanner in= new java.util.Scanner(System.in); System.out.println("type a name"); String line=in.nextLine(); System.out.println("type a number"); int num=in.nextInt(); System.out.println("read: "+line+" "+num); Read a line and a number and save what you read in newly created variables

Input nextLine reads text until next linebreak, returns the text and skips the linebreak nextInt skips spaces and newlines until start of a number, it reads and returns the number Notice that java and DOS does not read anything until you have finished a line. After a nextInt call the next symbol is probably a newline character.

Input input via dialog windows String name= javax.swing.JOptionPane.showInputDialog( "type a name"); String num = javax.swing.JOptionPane.showInputDialog( "type a number"); javax.swing.JOptionPane.showMessageDialog( null,"read: "+name+" "+num); Read a line and a number and save what you read in newly created variables

Java programs public class Hello{ public static void main(String args[]){ System.out.println(”Hello world”); } Public: you can hide stuff from other parts of your program. Here: everything can be seen everywhere static: some stuff may only exist for some of the time a program is executed. Here: it exists all the time void: methods may return values. Here: it does not return anything. String args[]: When you start a program it may have some command line arguments (you drop a file on a program etc). Here: it is not used.

Objects and classes Next Friday: Objects and classes JC chapter 2 and 3, (CCJ chapter 2) JC P , P3.7 (CCJ P2.5-P2.9, P2.11). First home assignment, Exercise JC P3.6 (CCJ P2.10) is to be handed in 26th September 13.00