JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

IT151: Introduction to Programming
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
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.
Your First Java Program: HelloWorld.java
Object Oriented Programming in JAVA
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
Chapter 1: Introduction
Chapter 1 These slides for CSE 110 Sections are based in part on the textbook-authors’ slides, which are copyright by the authors. The authors state that.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Lecturer: Fintan Costello Welcome to Hdip 001 Introduction to Programming.
CHAPTER 1 INTRODUCTION GOALS  To understand the activity of programming  To learn about the architecture of computers  To learn about machine code and.
Java Intro. A First Java Program //The Hello, World! program in Java public class Hello { public static void main(String[] args) { System.out.println("Hello,
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
1 Building Java Programs Chapter 1: Introduction to Java Programming These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may.
Unit 2: Java Introduction to Programming 2.1 Initial Example.
Introducing Java.
CS107 Introduction to Computer Science Java Basics.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Chapter 1 CSIS-120: Java Intro. What is Programming?  A: It is what makes computer so useful.  The flexibility of a computer is amazing  Write a term.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
POS 406 Java Technology And Beginning Java Code
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.
3 Major Steps for Creating/Running a Java Program You write the source code for the program and save it as a.java file. You compile the.java program using.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class.
Chapter 2: Java Fundamentals
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
A compiler is a computer program that translate written code (source code) into another computer language Associated with high level languages A well.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
CSC 110 – Intro to Computing - Programming
CS 177 Recitation Week 1 – Intro to Java. Questions?
ITP 109 Week 2 Trina Gregory Introduction to Java.
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
1/16: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Computer Science I Lab 1 ISMAIL ABUMUHFOUZ | CS 180.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
Chapter 1 – Introduction
John Woodward A Simple Program – Hello world
CSC201: Computer Programming
GC101 Introduction to computer and program
Console Output, Variables, Literals, and Introduction to Type
Intro to Java.
String Output ICS 111: Introduction to Computer Science I
Chapter 3 Classes and Objects
Fundamentals of Programming
Java Intro.
Computer Programming-1 CSC 111
© A+ Computer Science - Basic Java © A+ Computer Science -
Presentation transcript:

JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING

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 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 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 Basic Output Commands print() println()

GCOC – A.P. Computer Science A System.out.print( " Hello" ); object / referencecommand / method OUTPUT Hello System is the class name.out is an object that prints characters on the console window (black window on the screen). println is a method, or behavior, that the System.out object carries out. The characters enclosed in double quotation marks and are called a string. The string is printed in the console window. Each statement in a program ends with a semicolon (;). Try this in the interactions pane of Dr. Java. You should get the output to the left.

GCOC – A.P. Computer Science A Type the following into java: public class TestOutputs { public static void main(String [] args) { System.out.print("Hello"); } OUTPUT HelloHello

GCOC – A.P. Computer Science A public class TestOutputs { public static void main(String [] args) { System.out.println("Hello"); System.out.print("Hello"); } OUTPUT Hello

GCOC – A.P. Computer Science A Try the statements below in your TestOutputs program. Be sure to run each one and not any differences. Pay close attention to the difference between print and println.

GCOC – A.P. Computer Science A Java provides a facility for displaying special characters in a string. These special characters are indicated by placing a backslash (\) in the string. For example, since double quotation marks are used to indicate the start and end of a string, there is no obvious way to include quotation marks within a string. Therefore, the backslash must be used as in the statement: System.out.println(“You say \”Goodbye,\” and I say \“Hello.\””); Try this in the TestOutputs program. It should display: You say "Goodbye," and I say "Hello.“ The double quotation marks that follow the backslashes are displayed rather than interpreted as ending the string. The combination of symbols is called an escape character. The idea is that it escapes from the normal interpretation of characters in a string.

GCOC – A.P. Computer Science A Another special escape character is the end-of-line character. This is indicated by \n and can replace the use of –ln in println. For example: System.out.print(“This is the first line,\n”); System.out.print(“and this is the second line.”); Try this in the TestOutputs program. Displays: This is the first line, and this is the second line.

GCOC – A.P. Computer Science A System.out.println( " \\hello\ " / " ); \\Prints out \ \“Prints out “ \’Prints outs ’ \nGoes to next line \tTab(moves over 8 spaces OUTPUT \hello"/

GCOC – A.P. Computer Science A What is the output? (Attempt to answer the questions first, then type each into the interactions pane in Dr. Java to confirm your answers). System.out.println( “h\tello”); System.out.println( “hel\\lo\””); System.out.println( “hel\nlo”);