A Java Syntax Primer Yong Choi School of Business CSU, Bakersfield.

Slides:



Advertisements
Similar presentations
Fundamental Programming Structures in Java: Control Flow, Arrays and Vectors.
Advertisements

Local Variables and Scope Benjamin Fein. Variable Scope A variable’s scope consists of all code blocks in which it is visible. A variable is considered.
PL/SQL.
Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
CSE 115 Week 11 March , Announcements March 26 – Exam 7 March 26 – Exam 7 March 28 – Resign Deadline March 28 – Resign Deadline Lab 7 turned.
Structure of a C program
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
Repetition Statements repeat block of code until a condition is satisfied also called loops Java supports 3 kinds of loops: while statement – repeats a.
Review… Yong Choi BPA CSUB. Access Modifier public class HelloWorldApp –More detailes of Java key (reserved) wordJava key (reserved) word –The keyword,
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
1 CS 105 Lecture 3 Constants & Expressions Wed, Jan 26, 2011, 4:15 pm.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Looping Yong Choi School of Business CSU, Bakersfield.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
TODAY’S LECTURE Review Chapter 2 Go over exercises.
Hello AP Computer Science!. What are some of the things that you have used computers for?
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
CSC 330 E-Commerce Teacher Ahmed Mumtaz Mustehsan Ahmed Mumtaz Mustehsan GM-IT CIIT Islamabad GM-IT CIIT Islamabad CIIT Virtual Campus, CIIT COMSATS Institute.
2440: 211 Interactive Web Programming Expressions & Operators.
H.Melikian Introduction on C C is a high-level programming language that forms the basis to other programming languages such as C++, Perl and Java. It.
The Java Programming Language
Control Structures – Selection Chapter 4 2 Chapter Topics  Control Structures  Relational Operators  Logical (Boolean) Operators  Logical Expressions.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
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.
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
Java Programming Constructs 3 MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
CPS120: Introduction to Computer Science Decision Making in Programs.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions.
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Introduction to Java Java Translation Program Structure
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Basic Java Syntax COMP 401, Spring 2014 Lecture 2 1/14/2014.
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
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.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
CS170 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Loops in Java.
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Section 3.2c Strings and Method Signatures
Engineering Innovation Center
Chapter 3: Understanding C# Language Fundamentals
Chapter 19 JavaScript.
Control Structures – Selection
Arrays, For loop While loop Do while loop
2.1 Parts of a C++ Program.
Conditional Statements
Chapter 8: More on the Repetition Structure
Statements and expressions - java
CISC124 Labs start this week in JEFF 155. Fall 2018
Chapter 2: Introduction to C++.
CMPE212 – Reminders The other four assignments are now posted.
Comments Any string of symbols placed between the delimiters /* and */. Can span multiple lines Can’t be nested! Be careful. /* /* /* Hi */ is an example.
Chap 2. Identifiers, Keywords, and Types
Corresponds with Chapter 5
Presentation transcript:

A Java Syntax Primer Yong Choi School of Business CSU, Bakersfield

Class Names  Descriptive  Case sensitive  Camelback: OrderLineItem  Start with upper case letter Each Class must be stored in a file of the same name with the suffix ‘.java’: OrderLineItem.java

Basic Layout of a Class Package statement Import Statements Class declaration { Class-level variable declarations Method declaration { Method statements } Method declaration { Method statements }

Statements All the work in a Java class happens in statements. Every statement ends in a semicolon. A statement can cross multiple lines (but cannot break in the middle of a string literal). Statements live inside of code blocks.

Code Blocks Code blocks live inside of various kinds of declarations: Class Method Try Catch Conditional Iteration

Code Blocks Each code block is delimited by curly brackets Note the position of opening and closing brackets in sample code

Code Blocks Method code blocks can contain Local variable declarations Statements Conditional declarations, each with its own code block Iteration (loop) declarations, each with its own code block Try and Catch declarations, each with its own code block

Code blocks Code blocks inside of declarations can in turn contain: Local variable declarations Statements Conditional declarations, each with its own code block Iteration (loop) declarations, each with its own code block Try and Catch declarations, each with its own code block

Code Blocks and Data Variables A variable is accessible only within its own code block (which includes any other code blocks nested within it) A local variable overrides like-named variables in a higher level code block A variable is deleted at the end of the code block within which it was declared

Comments /* This is a comment that can span multiple lines */ // This comment lasts till end of line

Comments /* This nested comment won’t work /* Because the second start symbol is ignored and the first end symbol ends the whole comment */ so this is not part of the comment */

Expressions An expression is any part of a statement that can be evaluated into a single value An example would be an arithmetical expression: eg, 2*3 evaluates to 6.

Expressions Expressions are used constantly in Java. Every variable reference is really an expression that evaluates to the value of the variable. Any operation (manipulation of variables using operators) is an expression. Any method invocation that returns a value can be considered an expression.

Expressions Expressions can be nested Nested expressions are evaluated from the inside out Example: intBookID = ((Integer.valueOf((String)htFields.get(” BookID"))).intValue()); Above is fine (see bold and underlined) But below is not OK. There is a syntax error. intBookID = ((Integer.valueOf((String)htFields.get( ”BookID"))).intValue());