JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม Email:

Slides:



Advertisements
Similar presentations
Programming Languages and Paradigms The C Programming Language.
Advertisements

Lecture 1 Introduction to Java Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
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.
Constants and Data Types Constants Data Types Reading for this class: L&L,
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
CMT Programming Software Applications
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.2 Expressions and Assignment Statement.
JavaScript, Third Edition
String Escape Sequences
Introduction to Programming G51PRG University of Nottingham Revision 2 Essam Eliwa.
2015/8/221 Data Types & Operators Lecture from (Chapter 3,4)
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
DAT602 Database Application Development Lecture 5 JAVA Review.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
The Java Programming Language
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
CPS120: Introduction to Computer Science
Java Structure import java_packages; class JavaClass { member variables declarations; void otherMethod( ) { } public static void main(String[]
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 Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Expressions An expression is a series of variables, operators, and method calls (constructed according to the syntax of the language) that evaluates to.
November 1, 2015ICS102: Expressions & Assignment 1 Expressions and Assignment.
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Introduction to Java Java Translation Program Structure
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Basic Java Syntax COMP 401, Spring 2014 Lecture 2 1/14/2014.
Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science.
Python Primer 1: Types and Operators © 2013 Goodrich, Tamassia, Goldwasser1Python Primer.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
By Mr. Muhammad Pervez Akhtar
What Is a Package? A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Java-02 Basic Concepts Review concepts and examine how java handles them.
Variables Variables:-
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.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
1.  Algorithm: 1. Read in the radius 2. Compute the area using the following formula: area = radius x radius x PI 3. Display the area 2.
COP 2800 Lake Sumter State College Mark Wilson, Instructor
Java Language Basics.
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
Yanal Alahmad Java Workshop Yanal Alahmad
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Selenium WebDriver Web Test Tool Training
University of Central Florida COP 3330 Object Oriented Programming
Java Programming: From Problem Analysis to Program Design, 4e
Starting JavaProgramming
Chapter 3 Introduction to Classes, Objects Methods and Strings
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Basics of ‘C’.
An overview of Java, Data types and variables
elementary programming
Chap 2. Identifiers, Keywords, and Types
Chapter 2 Primitive Data Types and Operations
Presentation transcript:

JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม

Object-Oriented Programming What is an Object? An object is a software bundle of related state and behavior Software objects are often used to model the real-world objects that you find in everyday life. Dogs have state (name, color, breed) and behavior (barking, wagging tail) An object stores its state in fields (variables in some programming languages) and exposes its behavior through methods (functions in some programming languages). Data Encapsulation- Hiding internal state and requiring all interaction to be performed through an object's methods current speed, current pedal cadence, and current gear

Object-Oriented Programming What is a Class? A class is a blueprint or prototype from which objects are created. A class models the state and behavior of a real-world object Your bicycle is an instance of the class of objects known as bicycles.

Object-Oriented Programming What is a Class?

Language Basics Variables Instant Variables (Non-Static Fields) objects store their individual states in "non-static fields“ Non-static fields are also known as instance variables because their values are unique to each instance of a class (to each object, in other words) Class Variables (Static Fields) A class variable is any field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated Local Variables local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class. Parameters public static void main(String[] args)

Language Basics Naming Variable names are case-sensitive. When choosing a name for your variables, use full words instead of cryptic abbreviations. the name you choose must not be a keyword or reserved word If the name you choose consists of only one word, spell that word in all lowercase letters. If it consists of more than one word, capitalize the first letter of each subsequent word. f your variable stores a constant value, such as static final int NUM_GEARS = 6, the convention changes slightly, capitalizing every letter and separating subsequent words with the underscore character.

Language Basics Primitive Data Types byte : The byte data type is an 8-bit signed two's complement integer. short : The short data type is a 16-bit signed two's complement integer. int : The int data type is a 32-bit signed two's complement integer. long : The long data type is a 64-bit signed two's complement integer. float : The float data type is a single-precision 32-bit IEEE 754 floating point. double : The double data type is a double- precision 64-bit IEEE 754 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. Data Type Default Value (for fields) byte0 short0 int0 long0L float0.0f double0.0d char'\u0000' String (or any object) null booleanfalse Fields that are declared but not initialized will be set to a reasonable default by the compiler. Local variables are slightly different; the compiler never assigns a default value to an uninitialized local variable.

Language Basics Literal A literal is the source code representation of a fixed value; literals are represented directly in your code without requiring computation. The integral types (byte, short, int, and long) can be expressed using decimal, octal, or hexadecimal number systems. Use 'single quotes' for char literals and "double quotes" for String literals. \b (backspace), \t (tab), \n (line feed), \f (form feed), \r (carriage return), \" (double quote), \' (single quote), and \\ (backslash).

Language Basics Arrays An array is a container object that holds a fixed number of values of a single type. Each item in an array is called an element Each element is accessed by its numerical index. an array declaration has two components: the array's type and the array's name. An array's type is written as type[], where type is the data type of the contained elements; the square brackets are special symbols indicating that this variable holds an array.

Language Basics Creating, Initializing, and Accessing an Array

Language Basics Copying Arrays and Multidimensional Arrays a multidimensional array is simply an array whose components are themselves arrays

Language Basics Assignment, Arithmetic, and Unary Operators The Simple Assignment Operator The Arithmetic Operators

Language Basics Assignment, Arithmetic, and Unary Operators The Unary Operator

Language Basics Equality, Relational, and Conditional Operators The Equality and Relational Operators

Language Basics Equality, Relational, and Conditional Operators The Conditional Operators

Language Basics Equality, Relational, and Conditional Operators The Type Comparison Operator instanceof

Language Basics Expresssions, Statements, and Blocks Operators may be used in building expressions, which compute values; expressions are the core components of statements; statements may be grouped into blocks. An expression is a construct made up of variables, operators, and method invocations, which are constructed according to the syntax of the language, that evaluates to a single value.

Language Basics Expresssions, Statements, and Blocks Statements are roughly equivalent to sentences in natural languages. A statement forms a complete unit of execution. The following types of expressions can be made into a statement by terminating the expression with a semicolon (;). Assignment expressions Any use of ++ or -- Method invocations Object creation expressions

Language Basics Expresssions, Statements, and Blocks A block is a group of zero or more statements between balanced braces and can be used anywhere a single statement is allowed

Language Basics Control Flow Statements The statements inside your source files are generally executed from top to bottom, in the order that they appear. Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code. the decision-making statements (if-then, if-then-else, switch) the looping statements (for, while, do-while) the branching statements (break, continue, return)

Language Basics The if-then and if-then-else Statements The if-then Statement The if-then-else Statement

Language Basics The switch Statement A switch works with the byte, short, char, and int primitive data types. An if-then-else statement can be used to make decisions based on ranges of values or conditions, whereas a switch statement can make decisions based only on a single integer or enumerated value.

Language Basics The switch Statement

Language Basics The while and do-while Statements The while Statement The do-while Statement

Language Basics The for Statements The initialization expression initializes the loop; it's executed once, as the loop begins. When the termination expression evaluates to false, the loop terminates. The increment expression is invoked after each iteration through the loop; it is perfectly acceptable for this expression to increment or decrement a value.

Language Basics Branching Statements The break Statement (unlabeled/labeled)

Language Basics Branching Statements The continue Statement (unlabeled/labeled)

References l/index.html ConvTOC.doc.html