Writing Methods. Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts.

Slides:



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

Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Classes  All code in a Java program is part of a class  A class has two purposes  Provide functions to do work for the programmer  Represent data.
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.
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.
 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
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,
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
 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.
Assembler Compiler Interpreter ASSEMBLER To convert the assembly language into machine code. Translate mnemonic operation codes to their machine language.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Java Programming, 3e Concepts and Techniques Chapter 2 - Part 2 Creating a Java Application and Applet.
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Putting Applets into Web Pages.  Two things are involved in the process of putting applets onto web pages ◦ The.class files of the applet ◦ The html.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Chapter 1: Introduction to Programs, and Java 1. Objectives To review programs (§ ). To understand the relationship between Java and the World Wide.
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.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
How to Run a Java Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
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.
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.
Working with arrays (we will use an array of double as example)
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use Swing components to build the GUI Use proper naming conventions for classes.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
22-July-2002cse142-13B-Development © 2002 University of Washington1 Development Tools CSE 142, Summer 2002 Computer Programming 1
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
1 Installing Java on Your PC. Installing Java To develop Java programs on your PC: Install JDK (Java Development Kit) Add the directory where JDK was.
Creating a Java Application and Applet
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use simple Output statements Understand the different types and uses of comments.
Methods.
11 ITI 1120 Lab # 2 Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
CSC 110 – Intro to Computing - Programming
Invoking methods in the Java library. Jargon: method invocation Terminology: Invoking a method = executing a method Other phrases with exactly the same.
1/16: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
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.
 CSC 215 : Procedural Programming with C C Compilers.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
Computer Programming Your First Java Program: HelloWorld.java.
John Woodward A Simple Program – Hello world
GC101 Introduction to computer and program
Installing and running the local check projects in Eclipse
Intro to Java.
Writing Methods.
How to Run a Java Program
Java Intro.
Creating your first C program
How to Run a Java Program
Constructors, GUI’s(Using Swing) and ActionListner
Introduction to Java Brief history of Java Sample Java Program
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
Running a Java Program using Blue Jay.
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Computer Programming-1 CSC 111
Introduction to Programming - 1
© A+ Computer Science - Basic Java © A+ Computer Science -
How to Run a Java Program
Presentation transcript:

Writing Methods

Create the method Methods, like functions, do something They contain the code that performs the job Methods have two parts

Create the method The first part is called the Header modifier return name public void message( ) { open & closing braces }

Methods have two parts The second part is called the Body The body contains the lines of code that instruct the computer what to do You can have as many lines of code in the body as you want

Methods have two parts This Body has one line of code It tells the computer to print to the screen the text that is inside the set of double quotes public void message( ) { System.out.println(); System.out.println(“java is not kawfy”); }

Create a Class To use the method we need to create a simple class We put the method inside the class The class can have as many methods as you wish The class also has a Header and a Body

Create a Class The first part is called the Header modifier structure name public class MyClass { open & closing braces }

Create a Class The second part is called the Body The body contains one or more methods public class MyClass { public void message() { System.out.println(); System.out.println(“java is not kawfy”); }

Create an Application An Application is an executable program It uses the methods of different classes to execute the program Some methods are from the Java Class Library Other methods are from the Classes that We wrote

Create an Application We will create an object (instance) of the class We will call (invoke) a method of the class The Application class also has a Header and a Body The Application has one method named main

Create an Application Syntax: public class Morty { public static void main(String [] args) { MyClass mc = new MyClass(); mc.message(); }

Compile and Run Compile … correct any syntax errors Run … check for correct output –If necessary make any corrections –Then recompile and rerun.

1-compile 2-run 3-output

You will need to download a text editor You will need to download the latest version of Java You will need to reset the Path variable You will then be ready to roll

To Edit (add or delete) the PATH of the Windows O/S 0- Start 1- Settings 2- Control Panel 3- System 4- System Properties (dialog box) 5- Advanced (tab) 6- Environment Variables… 7- User (System variables) You can edit a current variable You can add/delete Delimiter is a semi-colon

The Path should be edited by inserting the following line at the very beginning: C:\ program files\java\jdk1.5.0_06\bin; Make sure you put the semi-colon (delimiter) right after the word “bin”