Statements and expressions - java

Slides:



Advertisements
Similar presentations
C++ Statements represent the lowest-level building blocks of a program and it may be like:. A simple statement is a computation terminated by a semicolon.
Advertisements

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.
IT151: Introduction to Programming
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Declaring Variables You must first declare a variable before you can use it! Declaring involves: – Establishing the variable’s spot in memory – Specifying.
CMT Programming Software Applications
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
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.
Classes CS 21a: Introduction to Computing I First Semester,
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Chapter 2: Java Fundamentals
Primitive Variables.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
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.
Primitive Variables.
Chapter 2 Variables.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
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.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
MIT AITI Lecture 2 The of Java In the following lectures you will learn the basic structures that make up the Java programming language: »Variables.
Java-02 Basic Concepts Review concepts and examine how java handles them.
1 2. Program Construction in Java. 01 Java basics.
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
A Sample Program #include using namespace std; int main(void) { cout
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Chapter 1.2 Introduction to C++ Programming
Chapter 2 Variables.
Chapter 1.2 Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Yanal Alahmad Java Workshop Yanal Alahmad
Chapter 2 part #1 C++ Program Structure
Computer Programming Methodology Introduction to Java
Variables, Printing and if-statements
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to CS Your First C Programs
2.1 Parts of a C++ Program.
Variables ICS2O.
Chapter 2 - Introduction to C Programming
Chapter 2 Variables.
Chapter 2 - Introduction to C Programming
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Tutorial 10: Programming with javascript
Chapter 2 - Introduction to C Programming
In this class, we will cover:
Unit 3: Variables in Java
Chapter 2 Variables.
Introduction to C Programming
Variables and Constants
Presentation transcript:

Statements and expressions - java

ABCs of Programming A java program is made up of classes and objects, which are made up of methods and variables. Methods are made up of statements and expressions – the smallest elements of java programming. Looking at the basics of Java code Statement – simple command that causes something to happen int weight – 225; System.out.println (“Lincoln High School is cool!”); song.duration = 230; Statement that produces a value is an expression The value produced is the return value Statements are terminated with a semicolon ;

Statements - continued In theory, more than one statement can be put on a line, best not to. Statements are grouped using an opening brace { and a closing brace } A group of statements between the characters is a block.

Variables and Data Types Java has three kinds of variables Instance variables – define an object’s attributes Class Variables – define the attributes of an entire class of objects Local Variables – only used inside a method We will work with local variables first. In java, you must create a variable by giving it a name and declaring its type. The type is listed first, followed by the name. EXAMPLES: int loanLength; String message; boolean gameOver;

Variables and data types EXAMPLES: int loanLength; String message; boolean gameOver; int represents integers String is an object that holds text boolean is used for Boolean true/false values Local variables can be declared at any place inside a method, BUT, they must be declared before they can be used. You can create several variables of the same type on the same line. String city, street, state;

Variables - continued Variables can be assigned a value when created by using an equal = sign followed by the value. You must give values to local variables before you use them in a program, or the program won’t compile successfully. NAMING VARIABLES – Names must start with a letter, an underscore character _ or a dollar sign $ Variables CANNOT start with a number. camelCase naming convention is best.

Comments Comments are essential to good programming. Comments help to organize and provide information for you and those working with you I require that all programs be properly commented – get used to it!! Single line comment two slashes // Everything from // to end of line is a comment Multi-line comments begins with /* and ends with */. Everything between them is a comment