Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Java Programming Class 1

Uploaded by

Raima Falor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Java Programming Class 1

Uploaded by

Raima Falor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Java Programming

class 1
What is a program?
● Set of Instructions ● Directions
● Ingredients ○ Statements
○ Variables ○ Execution
■ Numbers
■ Text
Anatomy of a class

Every program must have…

- At least one Class


- At least one main Method
public class MyProgram{

Public → public so everyone can


access it
Anatomy of a Class → it’s a class
class MyProgram → name of the class

{ → opening curly brace of the


class
Public static void main (String[] args)

Static → covered later

Void → return type


Anatomy of a
Main → name of the method
main method
String[]args → arguments, covered
later

{ → opening brace of the method


System.out.print(“Hello World”);

System.out.print → print command

Print Statement (“Hello World”) → the string you want to


print

; → every statement must end in a


semicolon
Complete Program

public class MyProgram {

public static void main (String[] args) {

System.out.print(“Hello World”);

}
Variable Types
Integer → Number (1, 2, 3, -1, 40, 526)
Float → Decimal Number (2.25, 0.56, 29.48)
Boolean → True and False
String → Text (“Hello”, “this is a string”, “NASA”)
Character → Single Character ( ‘A’, ‘b’ )
Creating Variables
int apples = 5;

int oranges = 3;

Usage:

System.out.print(apples);

int fruits = apples + oranges;


Creating Variables
Other Examples:

String town = “Cupertino”

boolean isRaining = true;

float waterAmount = 4.2;

int hours = 12;


Concatenation → combining
multiple strings to form a new string

String power = “Bat”;

Concatenation String person = “man”;

String superhero = power + person;

System.out.println(superhero);

// prints out Batman


String superhero = “Bat” + “man”

Punctuation

String first = “New ”;


Concatenation
String second = “York”;

System.out.print(first + second);

// prints out New York


Comments
● Notes for ourselves
○ To describe the usage of the code
// calculate total profit for the week
int profit = nickels + dimes + quarters + dollars;
Arithmetic Operators

+ Addition < Less Than


- Subtraction
> Greater Than
* Multiplication
/ Division
== Equal To
% Modulus != Not Equal To
Review
Homework

● Review Slides
● Assignment will be emailed to you after
class
○ Due before tomorrow’s class

You might also like