Software Practice 1 Basic Grammar

Similar documents
Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision

Java Loop Control. Programming languages provide various control structures that allow for more complicated execution paths.

Software Practice 1 - File I/O

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

Software Practice 1 - OOP (1) Class and Method

Programming with Java

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Software Practice 1. Course Overview Lecture Schedule Today s Task Contact

Getting started with Java

Computational Expression

Fall 2017 CISC124 9/16/2017

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

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Software Practice 1 - Multithreading

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Introduction to Programming Using Java (98-388)

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Accelerating Information Technology Innovation

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.

Introduction to Java & Fundamental Data Types

Java Notes. 10th ICSE. Saravanan Ganesh

JAVA OPERATORS GENERAL

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

3. Java - Language Constructs I

Software Practice 1 - Error Handling

Software Practice 1 - OOP (3) API

Introduction to Java

JAVA Programming Fundamentals

More Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

The Java language has a wide variety of modifiers, including the following:

Input. Scanner keyboard = new Scanner(System.in); String name;

DM550 Introduction to Programming part 2. Jan Baumbach.

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Computer Components. Software{ User Programs. Operating System. Hardware

COMP 202 Java in one week

Values and Variables 1 / 30

Section 2.2 Your First Program in Java: Printing a Line of Text

13 th Windsor Regional Secondary School Computer Programming Competition

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

BASIC ELEMENTS OF A COMPUTER PROGRAM

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

JAVA Ch. 4. Variables and Constants Lawrenceville Press

Lecture Set 2: Starting Java

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Java Programming Language. 0 A history

An overview of Java, Data types and variables

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Lecture Set 2: Starting Java

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.

Program Fundamentals

Object-Oriented Programming

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Computer Components. Software{ User Programs. Operating System. Hardware

Java Programming. Atul Prakash

Course Outline. Introduction to java

Chapter 3. Selections

Chapter 2: Basic Elements of Java

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

CHAPTER 5 VARIABLES AND OTHER BASIC ELEMENTS IN JAVA PROGRAMS

1. Find the output of following java program. class MainClass { public static void main (String arg[])

Preview from Notesale.co.uk Page 9 of 108

Connecting with Computer Science, 2e. Chapter 15 Programming II

NATIONAL UNIVERSITY OF SINGAPORE

CHAPTER 2 Java Fundamentals

Java Basic Datatypees

Expressions & Flow Control

Chapter 2. Elementary Programming

Java for Python Programmers. Comparison of Python and Java Constructs Reading: L&C, App B

Operators in java Operator operands.

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

CS313D: ADVANCED PROGRAMMING LANGUAGE

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Array. Lecture 12. Based on Slides of Dr. Norazah Yusof

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

TUGCE KEMEROZ - ASLI OZKAN - AYSE TARTAN. Week 12/02/ /02/2007 Lecture Notes:

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

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Java Identifiers, Data Types & Variables

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

PROGRAMMING FUNDAMENTALS

Zheng-Liang Lu Java Programming 45 / 79

CS 231 Data Structures and Algorithms, Fall 2016

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Getting started with Java

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

Fundamentals of Programming Data Types & Methods

CHAPTER 7 ARRAYS: SETS OF SIMILAR DATA ITEMS

Bjarne Stroustrup. creator of C++

Data Types, Literals, Operators

Full file at

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

Fundamentals of Programming CS-110. Lecture 2

Transcription:

Software Practice 1 Basic Grammar Basic Syntax Data Type Loop Control Making Decision Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee (43) 1

2 Java Program //package details public class ClassName { } Type classvariablename; public void methodname(arguments) { Type localvariablename; } public static void main(string args[]) { statements; }

3 Basic Syntax Case Sensitivity Java is case sensitive, which means identifier Hello and hello would have different meaning in Java. Class Names For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example: class MyFirstJavaClass Method Names All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example: public void mymethodname()

4 Basic Syntax (cont d) Program File Name Name of the program file should exactly match the class name. Example: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java' public static void main(string args[]) Java program processing starts from the main() method which is a mandatory part of every Java program.

5 Java Identifiers All Java components require names. Names used for classes, variables, and methods are called identifiers. In Java, there are several points to remember about identifiers. They are as follows All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). After the first character, identifiers can have any combination of characters. A keyword cannot be used as an identifier. Most importantly, identifiers are case sensitive. Examples of legal identifiers: age, $salary, _value, 1_value. Examples of illegal identifiers: 123abc, -salary.

6 Java Modifiers Like other languages, it is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers Access Modifiers default, public, protected, private Non-access Modifiers final, abstract, strictfp We will be looking into more details about modifiers in the 4 th week.

7 Java Keywords Keywords are reserved words in Java. These reserved words may not be used as constant or variable or any other identifier names. You can check every keywords on following link https://www.tutorialspoint.com/java/java_basic_synt ax.htm abstract assert boolean break byte case catch char class const continue default

8 Primitive Data Types Kinds of values that can be stored and manipulated byte : 8-bit signed two s complement integer boolean : truth value (true or false) short : 16-bit signed two s complement integer int : 32-bit signed two s complement integer long : 64-bit signed two s complement integer float : single-precision 32-bit IEEE 754 floating point double : double-precision 64-bit IEEE 754 floating point char : single 16-bit Unicode character

9 Variables A variable provides us with named storage that our programs can manipulate. Each variable in Java has a specific type, which determines the size and layout of the variable's memory; Form: TYPE NAME; Example: String foo;

10 Array Java provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. Syntax Type[] arrayrefvar; // preferred way. Type arrayrefvar[]; // works but not preferred way.

11 Array Declaration Java does not provide the dynamic size array which is able to resize the array dynamically. So, size of the array has to be specified before accessing the array. Syntax Type[] arrayrefvar = new Type[12];

12 Output to Console System.out //standard out System.out.println(data); System.out.print(data); System.out.println( Hello Java! ); System.out.print( Hello Java! );

13 Input from Keyboard System.in //standard in int b; b = System.in.read(); // read by ascii System.out.println(b);

14 Input from Keyboard ( 소곤소곤 ) Off the record import java.util.scanner; Scanner s = new Scanner (System.in); while (s.nextint ()) { }

15 Basic Operator Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups Arithmetic Operators Relational Operators Bitwise Operators Logical Operators Assignment Operators

16 Loop Control while loop for loop do while loop Loop control statements break; continue; Enhanced for loop in Java This is mainly used to traverse collection of elements including arrays.

17 Enhanced for Loop As of Java 5, the enhanced for loop was introduced. This is mainly used to traverse collection of elements including arrays. for(declaration : expression) { } // Statements

18 Enhanced for Loop Example public class Test { public static void main(string args[]) { int [] numbers = {10, 20, 30, 40, 50}; for(int x : numbers ) { System.out.print( x ); System.out.print(","); } System.out.print("\n"); String [] names = {"James", "Larry", "Tom", "Lacy"}; for( String name : names ) { System.out.print( name ); System.out.print(","); } } }

19 Decision Making if statement if statement Nested if statement switch statement The Conditional Operator (? : ) Expr1? Expr2 : Expr3;

20 [Lab Practice #1] Number System Converter Input decimal number from keyboard Convert input to binary, octal, hexadecimal number Print to console the results. Ex) Input decimal number : 2017 Binary number : 11111100001 Octal number : 3741 Hexadecimal number : 7e1

21 [Submit] Upload to i-campus Compress your.java file to zip file File name: studentid_lab01.zip Due date Today 23:59:59 Class 42 (3/12 Monday) Class 43 (3/14 Wednesday) Penalty: -10% of each lab score per one day