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.

Slides:



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

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.
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.
JAVA BASICS SYNTAX, ERRORS, AND DEBUGGING. GCOC – A.P. Computer Science A College Board Computer Science A Topics Covered Program Design - Read and understand.
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
© A+ Computer Science - public class CompSci { } All Java programs start with a class.
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
How to Create a Java program CS115 Fall George Koutsogiannakis.
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.
Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
PHY281Introduction to JavaSlide 1 Introduction to Java In this section we will learn how how to use Java and write our first Java Applet:  The Java Development.
“Introduction to Programming With Java”
Introducing Java.
2.2 Information on Program Appearance and Printing.
CSCI 273: Processing An Introduction. Programming Languages –An abstract "human understandable" language for telling the computer what to do –The abstract.
Chapter 1.4 Programming languages Homework Due: Monday, August 11, 2014.
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 –
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
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.
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
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.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
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:
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
ECE 122 Feb. 1, Introduction to Eclipse Java Statements Declaration Assignment Method calls.
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Application Architecture Using Java Hong Li. Introduction Developed by a team led by James Gosling at Sun Microsystem. Originally called Oak, designed.
CSc 201 Introduction to Java George Wells Room 007, Hamilton Building
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Java FilesOops - Mistake Java lingoSyntax
© 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.
11 ITI 1120 Lab # 2 Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
CSC 110 – Intro to Computing - Programming
CS 177 Recitation Week 1 – Intro to Java. Questions?
ITP 109 Week 2 Trina Gregory Introduction to Java.
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.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Introduction to programming in java
Computer Programming Your First Java Program: HelloWorld.java.
GC101 Introduction to computer and program
Chapter 3 GC 101 Java Fundamentals.
Chapter 2, Part I Introduction to C Programming
CompSci 230 Software Construction
Writing Methods.
String Output ICS 111: Introduction to Computer Science I
Chapter 3 Classes and Objects
Java Intro.
Computer Programming-1 CSC 111
© A+ Computer Science - Basic Java © A+ Computer Science -
Presentation transcript:

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 the compiler ( javac ). When you compile, it checks for syntax errors. When it successfully compiles, it creates a java bytecode file that ends in.class You interpret and execute the bytecode using the interpreter (the Java Virtual Machine, java )

IDE IDE stands for Integrated Development Environment. It is basically a fancy text editor that gives you easy access to the compiler and interpreter If you get an IDE, you still have to download the JDK before you can use it Although there are better IDEs out there, some of them are kind of complicated (like Oracle's NetBeans IDE and the Eclipse IDE) and others cost money (like developer versions of IDEs like JBuilder), so to make it easier we are going to use a useful, free, and easy one called JCreator If you want to try Oracle's NetBeans, you can download the "bundle" on the same page that you download the JDK from

© A+ Computer Science -

public class CompSci { } All Java programs start with a class.

© A+ Computer Science - public class CompSci { public static void main(String[] args) { System.out.println("Comp Sci!"); } OUTPUT Comp Sci!

© A+ Computer Science - public class CompSci { //open brace public static void main(String[] args) { System.out.println("Comp Sci!"); } } //close brace Braces – You gotta have ‘em! Every class and every method must have a { and a }.

© A+ Computer Science - public class CompSci { public static void main(String[] args) { System.out.println("Comp Sci!"); } You must put a semi-colon at the end of all Java program statements ( ; ).

© A+ Computer Science - Never put a ; before an open { brace ;{ //illegal }; //legal

© A+ Computer Science - public class CompSci { public static void main(String[] args) { System.out.println("Comp Sci!"); } Indent all code 3 spaces to make it easier to read.

© A+ Computer Science -

System.out frequently used methods NameUse print(x)print x and stay on the current line println(x)print x and move to next line down printf(s,x)print x according to s specifications

© A+ Computer Science - System.out.print( " compsci"); referencecommand / method OUTPUT compsci

© A+ Computer Science - System.out.print("compsci"); OUTPUT compscicompsci

© A+ Computer Science - System.out.println("compsci"); OUTPUT compsci

© A+ Computer Science - System.out.println("compsci"); OUTPUTcompsci

© A+ Computer Science -

System.out.println("c\tompsci " ); \nnewline \ttab \rcarriage return \bbackspace OUTPUT c ompsci

© A+ Computer Science - System.out.println("com\tpsci " ); OUTPUT com psci \nnewline \ttab \rcarriage return \bbackspace

© A+ Computer Science - System.out.println("comp\nsci"); OUTPUT comp sci \nnewline \ttab \rcarriage return \bbackspace

© A+ Computer Science -

\\outs \ \"outs " \’outs ’ System.out.println( " \\compsci\ " / " ); OUTPUT \compsci"/

© A+ Computer Science - \\outs \ \"outs " \’outs ’ System.out.println("\\'comp\'sci\'/"); OUTPUT \'comp'sci'/

© A+ Computer Science - Escape Sequences frequently used combinations NameUse \ttabs over five spaces \nmoves to front of next line \bdeletes previous character \rmoves to front of current line \\nets one backslash \ \"nets one double quote " \’nets one single quote ’

© A+ Computer Science - //single-line comments /* */block comments //this line prints stuff on the screen System.out.println("stuff");

© A+ Computer Science - //single-line comments /* */block comments /* this line prints stuff on the screen */ System.out.println("stuff");

© A+ Computer Science - System.out.printf("%s","compsci\n"); OUTPUT compsci

© A+ Computer Science -

Syntax errors occur when you type something in wrong, causing the code to not compile. //missing semicolon - ; expected System.out.println("stuff") //case problem – should be System system.out.println("stuff");

© A+ Computer Science - Runtime errors occur when something goes wrong while the program is running. //an out of bounds exception is thrown String s = "runtime_error"; System.out.println( s.charAt(15) );

© A+ Computer Science -

Importing There is a whole bunch of code already written for Java and included with it...why start from scratch with each program? To use pre-existing code, you need to import the class (ie, the file containing the code) at the top. To see a list of existing classes that you can use, go to the Java API (Application Program Interface) You can think of the classes in the API as building blocks you can use to make your programs The JOptionPane class is for simple GUIs...we'll use much more of it and many API classes in the future

Importing in Acition

© A+ Computer Science -