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.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
Begin Java Pepper. Objectives What is a program? Learn the basics of your programming tool: BlueJ Write a first Java program and see it run Make some.
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
Your First Java Program: HelloWorld.java
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
Chapter 2: Your First Program! Hello World: Let’s Program  All programs must have the extension.java  Our first program will be named: HelloWorld.java.
Lecturer: Fintan Costello Welcome to Hdip 001 Introduction to Programming.
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,
Outline Java program structure Basic program elements
CS107 Introduction to Computer Science Java Basics.
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:
Introducing Java.
Basics Programming Concepts. Basics A computer program is a set of instructions to tell a computer what to do Machine language = circuit level language.
CS107 Introduction to Computer Science Java Basics.
1 Chapter 2 First Java Programs Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
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.
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.
Programming Concept Chapter I Introduction to Java Programming.
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.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
Compiling and the Java Virtual Machine (JVM). The syntax of Pseudocode is pretty loose –visual validation encourages a permissive approach –emphasized.
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.
Floating point numerical information. Previously discussed Recall that: A byte is a memory cell consisting of 8 switches and can store a binary number.
Java Syntax and Output Java Part 3. public class CompSci { } All Java programs start with a class.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
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.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
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.
CSc 201 Introduction to Java George Wells Room 007, Hamilton Building
© 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.
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.
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
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.
John Woodward A Simple Program – Hello world
GC101 Introduction to computer and program
Chapter 3 GC 101 Java Fundamentals.
Introduction to.
Java Intro III.1 (Fr Feb 23).
Writing Methods.
String Output ICS 111: Introduction to Computer Science I
Java Intro.
CSE 142, Spring 2012 Building Java Programs Chapter 1
Computer Programming-1 CSC 111
© A+ Computer Science - Basic Java © A+ Computer Science -
Week 1 - Friday COMP 1600.
Presentation transcript:

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 and byte code. Describe the structure of a simple Java program. Write a simple program. Edit, compile, and run a program using a Java development environment. Format a program to give a pleasing, consistent appearance. Understand and fix compile-time errors.

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

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.

How Java Works!

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.

Assignment – Paper Airplanes Write down a set of instructions on how to fold a piece of paper into a paper airplane. Write these instructions in the Discussions under the heading Paper Airplanes. You are to choose a classmates’ instructions, and follow the directions exactly as they are written! Respond to that classmate as to the success of your airplane based on his/her instructions. Revise your own instructions by posting a “corrected” set of instructions, based on the comments made about your original instructions. OK – Now on to some real Java programming!

public class BareBones { } // end class BareBones All Java programs start with a class.

public class CompSci { public static void main( String args [] ) { System.out.println(“Java Rules!"); } **Type this program in Dr. Java and run it. OUTPUT Java Rules!

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.

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

Never put a ; before an open { brace ;{ //illegal }; //legal

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.

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.

Type the following program in Dr. Java exactly as it is written below: // basic class example public class Hello World { public static void main(String args [ ]) { System.out.println(“Hello World!”); }

Basic Output Commands print() println()

System.out.print( " Hello" ); object / referencecommand / method OUTPUT Hello

System.out.print( " Hello"); OUTPUT HelloHello

System.out.println( " Hello"); OUTPUT Hello

System.out.println( " Hello"); OUTPUTHello

System.out.println( " hel\tlo\n " ); \nnewline \ttab \rcarriage return OUTPUT hel lo

System.out.println( " \\hello\ " / " ); \\Prints out \ \“Prints out “ \’Prints outs ’ OUTPUT \hello"/

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”);