Introduction to Programming G51PRG University of Nottingham Revision 1

Slides:



Advertisements
Similar presentations
What Is Java? The name Java is a trademark of Sun Microsystems
Advertisements

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.
Basic Java Constructs and Data Types – Nuts and Bolts
Basic Data Structures in Java (c) IDMS/SQL News
Introduction to programming in java. Input and output to screen with Java program Structure of Java programs Statements Conditional statements.
© Vinny Cahill 1 Writing a Program in Java. © Vinny Cahill 2 The Hello World Program l Want to write a program to print a message on the screen.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Introduction to Java Applications
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
1 Variables and Data Types. 2 Variable Definition a location in memory, referenced by a name (identifier), where data of a given type can be stored, changed,
CSci 1130 Intro to Programming in Java
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Java.
Chapter 9 Interactive Multimedia Authoring with Flash Introduction to Programming 1.
COMP 14 Introduction to Programming
CS 1 Introduction CS 1 Part 11. Hardware 1.Central Processing Unit (CPU) 2.Main Memory 3.Secondary Memory / Storage 4.Input Devices 5.Output Devices CS.
DATA TYPES, VARIABLES, ARITHMETIC. Variables A variable is a “named container” that holds a value. A name for a spot in the computer’s memory This value.
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Java Basics. 2 Compiling A “compiler” is a program that translates from one language to another Typically from easy-to-read to fast-to-run e.g. from.
CMT Programming Software Applications
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Hello, world! Dissect HelloWorld.java Compile it Run it.
Introducing Java.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
DAT602 Database Application Development Lecture 5 JAVA Review.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Introduction to Computer Systems and the Java Programming Language.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
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.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Introduction to Java Java Translation Program Structure
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Java Programming Language Lecture27- An Introduction.
Information and Computer Sciences University of Hawaii, Manoa
Dept of Computer Science University of Maryland College Park
Data types and variables
Introduction to the C Language
An Introduction to Java – Part I, language basics
Chapter 1: Computer Systems
Introduction to C++ Programming
Focus of the Course Object-Oriented Software Development
Chap 2. Identifiers, Keywords, and Types
Computer Programming-1 CSC 111
Presentation transcript:

Introduction to Programming G51PRG University of Nottingham Revision 1 Essam Eliwa

Revision 1 How Java works? Break up Of The HelloWorld program Java Data types Using Variables Expressions, Statements, and Blocks

Programming languages An interpreted language is a programming language whose programs are translated to machine code at the time of execution through using an interpreter program A compiled language is a programming language which need the use of compilers to generate executable machine code in order to run the program

executable machine code High Level Language code Compiled Languages executable machine code import java.lang.* --------------------- -------------------- ------- --- ------------- ---- import java.lang.* --------------------- -------------------- ------- --- ------------- ---- Compiler 0010010100110 100101010101 101010101 10101010 import java.lang.* --------------------- -------------------- ------- --- ------------- ---- import java.lang.* --------------------- -------------------- ------- --- ------------- ---- Source Code Print Hello World ------- --- ------------- ---- Run High Level Language code Hello World!

Interpreted Languages import java.lang.* --------------------- -------------------- ------- --- ------------- ---- import java.lang.* --------------------- -------------------- ------- --- ------------- ---- Interpreter import java.lang.* --------------------- -------------------- ------- --- ------------- ---- Hello World! import java.lang.* --------------------- -------------------- ------- --- ------------- ---- Source Code Print Hello World ------- --- ------------- ---- Run High Level Language code

Java language is both compiled and interpreted In-stead of translating Java programs into machine language, the Java compiler generates Java byte code Byte code is easy (and fast) to interpret, almost like machine language, yet it is also portable, thus it is possible to compile a Java program on one machine and run it on any other machine Java virtual machine is needed to run any java program

Java virtual machine A Java virtual machine (JVM) interprets compiled Java byte code for a computer's CPU so that it can perform a Java program's instructions Defines an abstract machine or processor. Once a Java virtual machine has been implemented for a given platform, any Java program can run on that platform

Running Java Programs javac java

HelloWorld Program /** * The HelloWorld class implements an application that * simply prints "Hello World!" to standard output. */ class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); }// main end } // class end

Break down of HelloWorld /** * The HelloWorld class implements an application that * simply prints "Hello World!" to standard output. */ class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); }// main end } // class end every application must contain a main method (The starting point of the program) The modifiers public and static can be written in either order yet the convention is to use public static Comments are ignored by the compiler but are useful to other programmers. The Java programming language supports three kinds of comments The keyword class begins the class definition for a class followed by its name. The code for each class appears between the opening and closing curly braces

Hello World Anything in these brackets is information given to the method to help it perform its job This means that this process has no return This is simply the name of the method This simply means that other files can use this method if they wish For now – just assume that this has to be there! public static void main (String[] args) { System.out.println ("Hello World!") ; }// main end Here is an example of using a method. In this case, we’re using the method that writes text on to the screen. This is us giving the method information it needs to complete it’s job. In this case, we’re telling it what to write! A semi-colon is used like a full stop. It indicates the end of a single instruction

Notes Java is case-sensitive public class HelloWorld is the declaration of a new class called HelloWorld. main is the entry point for the program, that is the point at which execution starts. The body of the class and main method is contained within the { and } symbols. Every statement which is an instruction to the computer must be ended with a semi-colon. main() and { and } are part of the layout of the program not instructions. White space layout (tabs, newlines, spaces etc) is not enforced but should be used sensibly to make the code more readable.

Typed Languages BankBalance ü 700 û HolderName John Smith

Primitive Data Types all variables must first be declared before they can be used byte: An 8-bit signed integer ( -128 to 127 ) short: A 16-bit signed integer. (-32,768 to 32,767 ) int: A 32-bit signed integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 long: A 64-bit signed integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807

Primitive Data Types float: A single-precision 32-bit floating point. double: a double-precision 64-bit floating point. boolean: The boolean data type has only two possible values: true and false. char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

Reference Data Types - Strings Typically, a reference is the memory address at which the object or array is stored. String str =“cat”; Can not use == for comparison use ‘equals’ method instead String x = "Hello"; String y = "World"; String z = "HelloWorld"; String a = x + y; System.out.println(a == z); System.out.println(a.equals(z));

Creating a Variable in Java To create a variable in java we simply specify the type and the name of the variable. The following defines a variable called “num” that holds integers. int num; To initialize the variable: num = 0; Can be done on one step: int num =0;

Creating a Variable in Java We have to create a variable before we can use it Creating variables simply warns the computer that it needs to allocate some of the RAM to storing your data. The more variables you create, the more RAM your program will use when it is run.

Simple Program class Demo { public static void main (String[] args) { int result = 1 + 2; // result is now 3 result = result - 1; // result is now 2 result = result * 2; // result is now 4 result = result / 2; // result is now 2 result = result + 8; // result is now 10 result = result % 7; // result is now 3 System.out.println(result); } // main end } // class end

Expressions, Statements, and Blocks Operators may be used in building expressions, which compute values. 5+(7*2) 5>9 Expressions are the core components of statements (ends with ; ) int x= 5+7; x++; System.out.println("Hello World!"); Statements may be grouped into blocks defined by starting { and ending with } { int x; x =0; System.out.println(“x value is” + x); }

Recommended Reading http://java.sun.com/docs/books/tutorial/java/nutsandbolts/index.html