Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class.

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

Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
J A V A SHASHI BHUSHAN. MAIN ISSUES Object Oriented Concepts Examples FAQs.
Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
BASIC JAVA. Hello World n // Hello world program public class MyFirstJavaProgram { public static void main(String args[]) { char c = 'H'; String s =
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
 To be able to write larger programs ◦ By breaking them down into smaller parts and passing data between the parts.  To understand the concepts of Methods.
16-Aug-15 Java Puzzlers From the book Java Puzzlers by Joshua Bloch and Neal Gafter.
Hello AP Computer Science!. What are some of the things that you have used computers for?
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Neal Stublen What's a class?  A class is comprised of a set of data and the actions taken on that data  Each action is represented.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
OOP (pre) Basic Programming. Writing to Screen print will display the string to the screen, the following print statement will be appended to the previous.
CSC1030 HANDS-ON INTRODUCTION TO JAVA Introductory Lab.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
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.
CS 139-Programming Fundamentals Lecture 11B - Arrays Adapted from a presentation by Dr. Rahman Fall 2014.
1 Basic Java Constructs and Data Types – Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C.
Coding Bat: Ends in ly Given a string of even length, return a string made of the middle two chars, so the string "string" yields "ri". The string.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
Building java programs, chapter 3 Parameters, Methods and Objects.
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
Lecture 10. Review (Char) Character is one of primitive data types of variable (such as integer and double) –Character variable contains one character.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Methods What is a method? Main Method the main method is where a stand alone Java program normally begins execution common compile error, trying.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Chapter 9 Introduction to Arrays Fundamentals of Java.
Object Oriented Programming Lecture 2: BallWorld.
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Java Programming Language Lecture27- An Introduction.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Primitive data types Lecture 03. Review of Last Lecture Write a program that prints the multiplication table of 5. class MultiplicationTable { public.
Java Fundamentals MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
Introduction to Computer Science What is Computer Science? Getting Started Programming.
Java String Methods - Codehs
Introduction to Programming using Java
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Topics introduced today (these topics would be covered in more detail in later classes) – Primitive Data types Variables Methods “for” loop “if-else” statement.
Information and Computer Sciences University of Hawaii, Manoa
Today’s topic: Arithmetic expressions.
Examples of Classes & Objects
Elementary Programming
Chapter 2 Elementary Programming
Lecture 2: Data Types, Variables, Operators, and Expressions
Computer Programming Methodology Introduction to Java
TK1114 Computer Programming
An Introduction to Java – Part I
Introduction to Robots and the Mind - Methods -
Starting Out with Java: From Control Structures through Objects
An Introduction to Java – Part I, language basics
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Scope of variables class scopeofvars {
A Java Application public class Hello { public static void main(String [] args) { System.out.println("Hello, World!"); } } public class.
Arrays in Java.
Object-Oriented Programming and class Design
Question 1a) What is printed by the following Java program? int s;
Introduction to java Part I By Shenglan Zhang.
More on iterations using
Presentation transcript:

Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class

Review ● Program Structure ● System.out.println(“hello!”); ● Variables ● Control – If-then-else – Loops

Review public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World from Robot laptop"); int i = 0; boolean b = true; while (b == true){ System.out.println("HelloWorld: " + i); i = i + 1; if(i > 10){ b = false; } System.out.println(“done with loop”); }

Incrementing an integer int j = 5; j = j + 1; System.out.println(“value: ” + j); j++; System.out.println(“value: “ + j);

The “For” loop for (j = 0; j < 20; j++){ //do some stuff }

Task 1 Use a “for” loop – print out “Hello World” 10 times

Subroutines ● like a subprogram ● you can call this subprogram from within your program ● you can pass variables to it ● you can return values from it ● allows an important concept called “abstraction”

Subroutine Example, Part 1 void main(){ int radius = 5; double area; area = calculateArea(radius); radius = 10; area = calculateArea(radius); }

Subroutine Example, Part 2 double calculateArea(int radius){ double area; area = 3.14 * (radius * radius) return area; }

Task 2 ● write a subroutine to calculate the circumference of a circle. ● print out the circumference of a circle with a radius of 5 ● print out the circumference of a circle with a radius of 20 ● print out the circumference of a circle with a radius of 23.3;

Subroutine Review public class HelloWorld { public static double calculateArea(int radius){ double x; System.out.println("inside calculateArea, radius: " + radius); x = 3.14 * radius * radius; return x; } public static void main(String[] args) { System.out.println("Hello World from Robot laptop"); double sheehyArea = calculateArea(6); System.out.println("my area was: " + sheehyArea); sheehyArea = calculateArea(10); }

String ● name some of the java primitive data types ● there is another “type” called “String” ● but..... ● it isn't really a type ● it is an “Object”. Hold that thought!

The “String” Class String myName = “Mr. Sheehy”; System.out.println(“my name is “ + myName); ● Each character in the string has an index – starting with 0 and counting up ● ok, so what is the big deal?

The String Class ● you can do operations on a String object!! ● String myName = “Mr. Sheehy”; ● System.out.println( “length: “ + myName.length()); ● System.out.println( “uppercase: + myName.toUpperCase());

The Java API ●

Task 3 ● declare and initialize a String object ● initialize it to your full name ● using the java api – get a new String that is a substring of your name – the new String should be only your middlename

For next time ● the String class introduces an important concept..... – Objects and “Object Oriented Programming”