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.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Introduction to programming in java. Input and output to screen with Java program Structure of Java programs Statements Conditional statements.
INTRODUCTION Chapter 1 1. Java CPSC 1100 University of Tennessee at Chattanooga 2  Difference between Visual Logic & Java  Lots  Visual Logic Flowcharts.
IT151: Introduction to Programming
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.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
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.
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
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
 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.
Begin Java having used Alice Pepper - Some slides from Alice in Action with Java.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Introduction to Computer Programming CSC171 – 001 Getting Started – Chapters 1 & 2 Professor Pepper (presentation adapted from Dr. Siegfried)
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
“Introduction to Programming With Java”
Introducing Java.
2.2 Information on Program Appearance and Printing.
Chapter 2 How to Compile and Execute a Simple Program.
Basics Programming Concepts. Basics A computer program is a set of instructions to tell a computer what to do Machine language = circuit level language.
Java: Chapter 1 Computer Systems Computer Programming II.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
CS107 Introduction to Computer Science Java Basics.
Welcome to the Lecture Series on “Introduction to Programming With Java”
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
The Java Programming Language
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.
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.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
The scope of local variables. Murphy's Law The famous Murphy's Law says: Anything that can possibly go wrong, does. (Wikipedia page on Murphy's Law:
Chapter 2: Java Fundamentals
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:
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:
Introduction to programming in the Java programming language.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
Mixing integer and floating point numbers in an arithmetic operation.
© 2004 Pearson Addison-Wesley. All rights reserved ComS 207: Programming I Instructor: Alexander Stoytchev
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
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
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
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.
Terms: Software  Set of instructions  aka programs  Operating System:  Special software whose job it is to translateinstructions into hardware instructions.
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
Programming what is C++
CSC201: Computer Programming
Object-Oriented Programming Using Java
Chapter 3 GC 101 Java Fundamentals.
Introduction to.
Chapter 2, Part I Introduction to C Programming
Intro to Java.
Writing Methods.
Hands-on Introduction to JAVA
MSIS 655 Advanced Business Applications Programming
Java Intro.
Building Java Programs
Computer Programming-1 CSC 111
Presentation transcript:

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 changes and see them run Understand basic program flow - Create two methods in one program

What Is Programming? Computers cannot do all the wonderful things that we expect without instructions telling them what to do. Program – a set detailed of instructions telling a computer what to do Programming – designing and writing computer programs Programming language – a language used to express computer programs. (Syntax & Vocab)

A Very Simple Java Program public class JavaWorld { public static void main(String[] args) { System.out.println ("This is my first Java program."); } Class header Method header statements Close braces mark the end Open braces mark the beginning

A First Program – What Does It Do? Prints the message This is my first Java program. Ends the line System.out.println ("This is my first Java program.");

6 public class { public static void main(String[] args) { ; ; ; ; } Every executable Java program consists of a class –that contains a method named main that contains the statements (commands) to be executed Structure of Java programs

Steps to create a program Design Code Compile Run Test

Make the Program Run Compile (translate to java byte code) Run (interpreter for that OS reads java byte code and translates for machine) Source x.java Compile (javac x.java) Object x.class Execute (java x) compileexecute outputsource code Hello.java byte code Hello.class

Development Environment Blue Jay Lets you enter code and run it to get results Download at: Instructions on syllabus

Exercise Add the line “Welcome to Java” When you run the program, you will see: This is my first Java Program. Welcome to Java. Extra: –Info: print() does not go to the next line –Try splitting Welcome to Java into two statements: “Welcome” and then “ to Java.”

Comments // -> comment line ex: // this is a comment /* xxx */  comment between marks ex: /* these are a bunch of comments x=y; that line above is meaningless */ Space liberally For you to do: Add some comments to your program and see it makes no changes

Add a method What: a set of statements that has a name you can call. Why: –deal with complex code –repeatedly call the same statements –Divide responsibility among programmers How: –Add a method header with { } following: Ex: public static void method1(){ } –Write the statements inside the { }. –Call the method a few times from your main routine ex: method1();

Example of a new method public class JavaWorld { public static void main(String[ ] args) { System.out.println ("This is my first Java program."); method1(); } public static void method1(){ System.out.println (“I love Java."); } YOU TRY: add method1 to your program and have your main method call method1 a few times. Have it call method1 before and after the “This is my first java program” line. Add another print statement to method1 and see what happens.

Escape Characters 1 BUT, I really want a double quote inside my string! \” is “ -  “abc\”def” -  abc”def \\ is \ -  “abc\def” -  abc\def

Escape Characters 2 How do I get new lines and tabs? \n= new line (go to beginning of next line) \r =carriage return (go to beginning of this line) \t = tab (go to next tab stop)

Escape characters in your program Insert \t inside the quotes of a print statement in your program  what prints? Insert a \\ inside the quotes of a print statement in your program  what prints? Now remove the ‘\’ and see that the program wont even compile.

Your toolset Basic setup Create and call methods Print to screen including escape commands Comments Here are the programming steps you exploredHere are the programming steps you explored