JAVA Practical 02 1. Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.

Slides:



Advertisements
Similar presentations
Introduction to Programming Java Lab 1: My First Program 11 January JavaLab1.ppt Ping Brennan
Advertisements

Introduction to Programming G51PRG University of Nottingham Revision 1
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
IT151: Introduction to Programming
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.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Your First Java Program: HelloWorld.java
Chapter 1: Introduction
How to Create a Java program CS115 Fall George Koutsogiannakis.
©2004 Brooks/Cole Chapter 1: Getting Started Sections Covered: 1.1Introduction to Programming 1.2Constructing a Java Program 1.3The print() and println()
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.
Computer Programming 12 Mr. Jean March 3 rd, 2014.
Introducing Java.
Chapter 2 Classes and Methods I Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Towson University COSC 236
Hello AP Computer Science!. What are some of the things that you have used computers for?
LESSON 2 CREATING A JAVA APPLICATION JAVA PROGRAMMING Compiled By: Edwin O. Okech [Tutor, Amoud University]
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 Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.
C# B 1 CSC 298 Writing a C# application. C# B 2 A first C# application // Display Hello, world on the screen public class HelloWorld { public static void.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
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.
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.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
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
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Week 1 - Friday.  What did we talk about last time?  Our first Java program.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
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:
Object Oriented Programming Lecture 3. Introduction  In discussing Java, some items need to be clarified  The Java programming language  The Java virtual.
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.
A First Simple Program /* This is a simple Java program. Call this file "Example.java".*/ class Example { // Your program begins with a call to main().
Output in Java Hello World!. Structure of a Java Program  All Java files in ICS3U1 have the following structure: class HelloWorld { }  Notice the open.
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
Anatomy of a Java Program. AnotherQuote.java 1 /** A basic java program 2 * 3 Nancy Harris, James Madison University 4 V1 6/2010.
Hello Computer Science!. Below is an example of a Hello World program in JAVA. While it is only three lines of code, there are many things that are happening.
Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
CSI 3125, Preliminaries, page 1 Compiling the Program.
CSc 201 Introduction to Java George Wells Room 007, Hamilton Building
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
© 2007 Lawrenceville Press Slide 1 Chapter 3 Classes and Objects 1. How is a class different from an object?
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.
CS 177 Recitation Week 1 – Intro to Java. Questions?
1/16: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
CS 106 Introduction to Computer Science I 01 / 24 / 2007 Instructor: Michael Eckmann.
CompSci 42.1Intro to Java Anatomy of a Class & Terminology Running and Modifying a Program.
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.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Java Programming Fifth Edition Chapter 1 Creating Your First Java Classes.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Computer Programming Your First Java Program: HelloWorld.java.
The eclipse IDE IDE = “Integrated Development Environment”
John Woodward A Simple Program – Hello world
CSE 190D, Winter 2013 Building Java Programs Chapter 1
Intro to Java.
Statements, Comments & Simple Arithmetic
Chapter 3 Classes and Objects
Java Intro.
Running a Java Program using Blue Jay.
How to Run a Java Program
Presentation transcript:

JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters 6. Case sensitivity 7. Syntax Errors

First Steps It is a good idea for to create a folder where we will save our programs So you simply create a folder in my documents and name it ‘My Java’ J Creator is then used to create our programs

JCreator In order to start programming we need to create a new file in Jcreator 1. Start up JCreator 2. Click on File > New > File 3. Click on Empty Java File 4. Name the file as ‘Practical02’ 5. Choose to save it in the folder you just created in My Documents

First Program Type in the following program What should this program output?

Compiling our Program When we compile our program we will be building our file To compile our program we need to press on the ‘Build File’ icon. If we have no errors it will show Process Complete

Executing our Program Executing means running our programs Once we compile it we can run our program by pressing the run icon

Program Output Once you press run a new window will open showing your programs output

Source-Code File The source-code file is the text file create when we save a program This file uses actual text which use humans can read

Class File A class file is the file created each time we compile a program The class file contains the code that the JVM (Java Virtual Machine) uses to run our programs.

Program Components The different parts of our programs

Comments Comments are used to remind the programmer what the code does. There are two type of comments; single line and multi-line. 1. Single line comments: only a single line. In order to create a single-line comment, // must be used before writing the comment. 2. Multi-line comments can be spread over a number of lines, these comments must start with /* and then end with */. //Program 1 : My First Program

Class The keyword class shows that a new class is being created Just after the keyword, there must be the name of the class, which is TestProgram in our program Then the curly brackets show where the code of the class begins and ends. class TestProgram

Main Method Every program must have one main method It is made up of : 1. public – this means that this method is available from outside the class 2. static – this method can be used without creating an instance of the class 3. void – this method does not return a value 4. main – the name of the method 5. String args[] – an array of type String which can accept a number of arguments in array args public static void main (String args[]){

Statement This statement tells the program to print Hello World! as the output println() : tells the program to move the cursor to the next line print(): tells the program to leave the cursor on the same line System.out.println("Hello World!");

Semi - colon All statements must end with a semi – colon The semi – colon lets the program know that the statement is over and can be run ;

Escape Characters These are used to edit the way the text is printed when using println() Escape CharacterWhat it is used for \’Display in a single quote \”Display in double quotes \\Display a backslash \nMove to a new line \tInsert a tab

Case sensitivity When programming in Java we have to be careful to make sure that everything is written correctly It is important to look out when writing words with capital letters and small letters If we write we will get an error… why? system.out.println("Hello World!");

Syntax Error An error in the code is called a Syntax error The code will not compile before all the errors are seen too Errors could be; 1. Not obeying the case sensitivity rule 2. Forgetting a semi – colon 3. Forgetting brackets… ect