JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.

Slides:



Advertisements
Similar presentations
1 pritisajja.info Unlocking the World of Java Programming….. Priti Srinivas Sajja February, 2014 Visit pritisajja.info for detail Future Technology for.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. OBJECTIVES FOR THIS UNIT Upon completion of this unit, you should be able to: Explain the Java virtual machine.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
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.
Object Oriented Programming in JAVA
CMT Programming Software Applications
Outline Java program structure Basic program elements
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
Introduction to a Programming Environment
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Hello, world! Dissect HelloWorld.java Compile it Run it.
CS107 Introduction to Computer Science Java Basics.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
Chapter 9 Interactive Multimedia Authoring with Flash - Introduction to Programming “Computers and Creativity” Richard D. Webster, COSC 109 Instructor.
Introducing Java.
 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.
DAT602 Database Application Development Lecture 5 JAVA Review.
Introduction to Python
Introduction to Programming Writing Java Beginning Java Programs.
CS107 Introduction to Computer Science Java Basics.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
Basics of Java IMPORTANT: Read Chap 1-6 of How to think like a… Lecture 3.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
CIT 590 Intro to Programming First lecture on Java.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
Introduction to Programming Writing Java Beginning Java Programs.
A variable is a storage location for some type of value. days 102 taxrate 7.75 int days = 102; double taxrate = 7.75; char grade = ‘A’; boolean done.
A compiler is a computer program that translate written code (source code) into another computer language Associated with high level languages A well.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
© A+ Computer Science - A reference variable stores the memory address of an object. Monster fred = new Monster(); Monster sally.
CPS120: Introduction to Computer Science Variables and Constants.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
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.
Basic concepts of C++ Presented by Prof. Satyajit De
The need for Programming Languages
Working with Java.
Introduction to the C Language
GC101 Introduction to computer and program
Chapter 3 GC 101 Java Fundamentals.
Console Output, Variables, Literals, and Introduction to Type
Data types and variables
Introduction to the C Language
String Output ICS 111: Introduction to Computer Science I
Variables ICS2O.
elementary programming
Anatomy of a Java Program
© A+ Computer Science - Variables & Data Types © A+ Computer Science - ©A+ Computer Science
Computer Programming-1 CSC 111
Presentation transcript:

JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING

GCOC – A.P. Computer Science A Vocabulary & Terms Computer programming Machine language Machine code Compiler Source code Integrated Development Environment (IDE) Statement Bytecode Java virtual machine (JVM) Class Object Reference Command Method

GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand a problem's description, purpose, and goals. Program Implementation - Console output (System.out.print/println) Program Analysis - Identify and correct errors. Computing Context - Major hardware components; Language translators/compilers ; Virtual machines

GCOC – A.P. Computer Science A How Java Works! 1. You create a source document using an established protocol (in our case, the Java language). 2. Then your program is run through a source code compiler. The source code compiler checks for errors and won’t let you compile until it’s satisfied that everything will run correctly. 3. The compiler creates a new document,coded into Java bytecode. Any device capable of running Java will be able to interpret/translate this file into something it can run. The compiled bytecode is platform independent. 4. The Java Virtual Machine (JVM) translates the bytecode into something the underlying platform understands, and runs your program. The next slide shows an illustration of this sequence.

GCOC – A.P. Computer Science A How Java Works!

GCOC – A.P. Computer Science A What is Computer Programming? Before we jump into Java, let’s talk a bit about exactly what computer programming is. Computer programming is the art of creating a set of instructions, called a computer program, for a computer. Computers have no judgment, so instructions must be detailed and unambiguous! Unfortunately, creating complex sets of unambiguous instructions is not easy. It requires both training and practice.

GCOC – A.P. Computer Science A public class BareBones { } // end class BareBones All Java programs start with a class.

GCOC – A.P. Computer Science A public class CompSci { public static void main( String args [] ) { System.out.println(“Java Rules!"); } OUTPUT Java Rules! Type this program in Dr. Java and run it. Then change String args [] to String [] args and run the program again. You should notice no change!

GCOC – A.P. Computer Science A public class CompSci { public static void main( String args [] ) { System.out.println(“Java Rules!"); } Every method and every class must have an opening ( { ) brace and a closing ( } ) brace.

GCOC – A.P. Computer Science A public class CompSci { public static void main(String args[]) { System.out.println(“Java Rules!"); } Every program statement is terminated with a semi-colon ( ; ).

GCOC – A.P. Computer Science A Never put a ; before an open { brace ;{ //illegal }; //legal

GCOC – A.P. Computer Science A public class CompSci { public static void main(String args[]) { System.out.println(“Java Rules!"); } Indent all code 3 spaces to make it easier to read.

GCOC – A.P. Computer Science A What is a Convention? In Java, a convention is an accepted practice, not necessarily a rule. Indenting 3 spaces is a Java convention that you will see in many textbooks. In reality, the compiler doesn’t really care about spacing! Spacing is for the human readers, not the computer.

GCOC – A.P. Computer Science A Conventions For Use In This Class You should download and print out a copy of the document Conventions, which is the next link. You must follow the conventions listed on this document in every program that you turn in for a grade! You will lose points on your programs if you do not follow these conventions!

GCOC – A.P. Computer Science A A reference variable refers to a location in memory that stores an object. Monster fred = new Monster(); Monster sally = new Monster(); In the above example Monster is a class. fred and sally are references to Monster objects. new is a keyword which is used to create an object. It is followed by the constructor method, which is the class name, and parenthesis. The first part: Monster fred – declares a reference variable to hold a Monster object. The second part: = new Monster(); - creates the Monster object, and assigns fred to the location where this object is in memory.

GCOC – A.P. Computer Science A fred Monster Monster fred = new Monster(); 0xF5 Monster fred creates a reference. new Monster(); creates the Monster at location 0xF5. The assignment operator (=) gives fred the address 0xF5 to store

GCOC – A.P. Computer Science A What is a variable?

GCOC – A.P. Computer Science A A variable is a storage location for some type of value. Type the statements below into the interactions pane. Type the name of the variable to see what is stored in the variable. What is stored in yesOrNo? days 102 yesOrNo int days = 102; double taxRate = 7.75; boolean yesOrNo; taxRate 7.75

GCOC – A.P. Computer Science A int days = 102; days 102 int days – declares days as a variable that will store integer values. = 102 assigns days to store the integer value 102.

GCOC – A.P. Computer Science A How do you name variables when defining them?

GCOC – A.P. Computer Science A When naming a variable follow these rules and conventions: Make the variable name meaningful. That means that L is not a meaningful variable name but length is meaningful. When reading your program, I shouldn’t be guessing what the variable is meant to hold. Start all variable names with a lower-case letter. Variable names may also contain letters, numbers and underscores. If a variable name is more than one word long, capitalize each of the other words without adding any spaces. Below are some examples of valid variable names: number sum32 testAverage area_Of_Trapezoid and below are some examples of invalid variable names: 2ndValue test Average question#2

GCOC – A.P. Computer Science A Which of these would be legal variable identifiers? int 1stYear; double jump Up; double feet2Inches; IDENTIFIER is a fancy word for variable.

GCOC – A.P. Computer Science A Java is case sensitive – it interprets upper and lower case letters as different letters. Brandon does not equal brandon. Brandon != brandon

GCOC – A.P. Computer Science A Keywords are reserved words that the language uses for a specific purpose. You cannot use keywords as identifier names. Some that you’ve seen are: int double return voidmain public static long break continue class You can find the complete list of keywords here: