Skip to Content

Translate Page

Use of arrow keys when focused on the Google language option field will translate site content on the fly. Use your enter key to review all options and choose your selection before applying.
McFarland School District
McFarland High (9-12)
  • McFarland High (9-12)
    • McFarland High School
    • Academic & Career Planning (ACP)
      • Youth Apprenticeship
    • Athletic & Activity Code of Conduct
    • Canvas Login
    • Clubs
    • Communications
    • Course Supply List
    • Daily Announcements
    • Daily Schedules
    • Family Handbook
    • Grading Handbook
    • Graduation Information
    • Library Media Services
    • Music
    • Office Staff
    • PBIS
    • Portfolio Resources
    • Progressive Behavior Response Plan
    • Report Suspicious Activity
    • School To Career
    • Spartan Headquarters
    • Special Education
    • Sports
      • Boys Teams
        • Baseball
        • Basketball
        • Football
        • Golf
        • Hockey
        • Lacrosse
        • Soccer
        • Swimming
        • Tennis
      • Coed Teams
        • Cross Country
        • Track & Field
        • Wrestling
      • Girls Teams
        • Basketball
        • Dance
        • Golf
        • Hockey
        • Lacrosse
        • Soccer
        • Softball
        • Swimming
        • Tennis
        • Volleyball
      • 24-25 Sport Registration-Athletic Code Video
      • Athletic & Activity Code of Conduct
      • Concussion & Sudden Cardiac Arrest Info
      • Infinite Campus Sport Registration Info Sheet
      • Parent Resources
      • Parent Transportation Form
      • Spartan Sport Sponsors
      • Uniform Care Info
      • WIAA Medical Eligibility Form
    • Staff Directory
    • Student Services
      • Transcript Request (former students)
    • Xello - Student
    • Web Design 1
      • Class Lessons
        • XHTML Tutorial
        • CSS Tutorial
        • Form Tutorial
        • Graphics
        • Dreamweaver
        • QuickMenu
        • Joomla!
      • Assignments
        • Site 1: Biography
        • Site 2: Fan Club
        • Site 3: Mixed Media
        • Site 4: Joomla!
      • Student Samples
        • Biography Sites
        • Fan Club Sites
        • Mixed Media Sites
        • Joomla! Sites
      • Helpful Sites
        • XHTML Help
        • CSS Help
        • Validation
        • QuickMenu
        • Joomla! Help
    • Web Design 2
      • Class Lessons
        • JavaScript Tutorial
        • PHP Tutorial
        • MySQL Tutorial
        • Admin - CMS
      • Assignments
        • Using JavaScript
        • For the Birds
      • Helpful Sites
        • JavaScript Tutorials
        • RegExp Help
        • Web Page Validation
    • Programming 1
      • Class Lessons
        • CLASS SET-UP
        • Logic Test
        • Class Preparation
        • Using BlueJ
        • --------------------
        • SET 1 LESSONS:
        • Printing
        • Variables
        • User Input
        • Random Number
        • Arithmetic
        • --------------------
        • SET 2 LESSONS:
        • If
        • Switch
        • --------------------
        • SET 3 LESSONS:
        • Looping
        • --------------------
        • SET 4-5 LESSONS:
        • Arrays
        • --------------------
        • SET 6 LESSONS:
        • String Manipulation
      • Problem Sets
        • Set 1: Basic Skills
        • Set 2: If & Switch
        • Set 3: Loops
        • Project: Craps
        • Set 4: Single Array
        • Set 5: Double Array
        • Set 6: Strings
      • Solution Sets
        • Problem Set 1
        • Problem Set 2
        • Problem Set 3
        • Problem Set 4
        • Problem Set 5
        • Problem Set 6
      • Helpful Sites
    • Programming 2
      • Class Lessons
        • Using BlueJ
        • What is an Object?
        • What is a Class?
        • GUI Programming
      • Problem Sets
        • Set 1 - Shapes
        • Set 2 - Exercises
        • Set 3 - Exercises
        • Set 4 - Exercises
        • Project - Adding
        • Set 5 - GUI by Hand
        • Project - NetBeans
        • Set 6 - NetBeans
        • Project - Life
        • Project - Slide Puzzle
        • Project - Matching
      • Solution Sets
        • Problem Set 1 (none)
        • Problem Set 2 (none)
        • Problem Set 3 (none)
        • Problem Set 4
  • Home
  • District
    • Referendum November 5, 2024
      • Impact Tax Calculator
    • Strategic Plan
    • School Board
      • Agendas, Minutes & Notices
      • Board Member Informational Brochure
      • District Policies
      • Meeting Calendar
      • Meeting Recordings
      • Members
      • Non-Discrimination Policy
      • Notice of Educational Options
      • Notices
      • Resolutions
    • Departments & Administration
      • District Administrator Message
        • Tarnutzer's Travels
      • Diversity, Equity, Inclusion & Belonging
      • Administrative Staff
      • Building & Grounds
        • Facility Use / Rental
      • Business Services
      • Finances
      • Health Services
      • McFarland Recreation Activities & Play (MRAP)
        • Current Events / News
        • Community Recreation Partners
      • Public Records Requests
      • School Nutrition
        • Lunch Menus
      • Special Education
        • What is Special Education?
        • Contact Information
        • Resources
      • Student Services
        • Community Resources
        • District Programs
        • Family Resources
        • Student Services Team Members
      • Summer School
      • Teaching & Learning
        • Assessments for Learning
        • Curriculum
        • Wisconsin Academic Standards
        • Early Literacy - Wisconsin Act 20
      • Transportation
        • Bus Safety Videos
        • StopFinder
    • Prospective Families & Staff
      • About McFarland
      • District Boundary Map
      • District Mission & Vision
      • Employment
      • Enrollment Process
        • Online Enrollment
      • Open Enrollment
      • Residency Questions
      • School and District Report Cards
    • Staff Resources
      • Assessment Calendar (District)
      • Assistive Technology
      • Branding/Logos
      • Building & Grounds Info Sheet
      • Calendar Dates - Staff 24-25
      • Calendar Dates - Staff 25-26
      • Canvas Login
      • Educator Effectiveness
      • Employee Assistance Program
      • Employee Handbook
      • FAQ - Employee Services
      • Field Trip Requests
      • Finance Forms
      • FMLA
      • Fundraising
      • Hiring Procedure
      • HR and Business Services
      • HR HERMAN
      • Infinite Campus Staff Login
      • Insurance
      • Maintenance & Facilities Requests
      • Mentoring Resources
      • Payroll Forms
      • PD Points Tracker
      • SeeSaw Staff Login
      • Skyward
      • Student Teacher
      • Substitute Request
      • Technology (IT) Help Desk
      • Technology Department
      • Technology Orientation
      • Time-Off
      • TSG Info & Timelines
      • Web Site Admin
      • WECAN Links
      • Xello - Staff Login
  • Families
    • All
      • 2024-2025 School Hours
      • 2024-2025 Calendar Dates
      • 2025-2026 Calendar Dates
      • Calendar - All District
      • Canvas Login
      • Communications
      • Daily Schedules
      • Emergency Protocol
      • Handbooks
      • McFarland Mobile App
      • Online Registration
        • Registration Documents
      • Safety
      • Safety and Bullying Tip Line - SUSO
      • School and District Report Cards
      • Social Media
      • Spartan Headquarters
      • Supply Lists
    • Students
      • Canvas Student Login
      • Library Resources
    • Parents/Guardians
      • Absence Reporting
      • Advanced Learner (GT)
      • Canvas Parent Login
      • Drug & Alcohol Resources
      • Dyslexia Information Guide
      • English Learners (EL)
        • Eligibility
        • Philosophy
        • DPI Language Levels
        • Resources
      • Gun Safety Resources
      • Human Growth & Development Booklet
      • Joining Forces for Families
      • McFarland Music Boosters
      • School Nutrition
      • Special Education
      • Transportation
      • Volunteer Application & Disclosure Form
      • Volunteer Handbook
      • Weather Cancellation Days
    • Important Links
      • ACT Prep
      • Drivers Ed
      • Google Apps
      • Infinite Campus
      • Lunch Menus
      • McFarland Public Library
      • Summer School
      • Work Permits
      • Xello - Student (w/Free ACT Method Test Prep
    • Other
      • McFarland Thistle
      • McFarland Youth Center
      • Outdoor Programs
        • Resources
      • McFarland School Forest
        • Bird Boxes
        • Bird Feeders
        • Bird Song Board
        • Fauna
        • Flora
        • Habitats
        • Silver Award
        • Our Supporters
  • Community
    • Community Pool
    • Facilities Use / Rental
    • McFarland Education Foundation (MEF)
    • McFarland Performing Arts Center (PAC)
    • McFarland Public Library
    • McFarland Recreation, Activities & Play(MRAP)
    • School Visitors
    • Summer School
    • Village of McFarland
  • Contact Us
    • District Office
    • School Offices
    • Staff Directory
    • Web Site Feedback
    • Spartan Shout Outs
  • A-Z Links
  • Staff Resources
  • Website Guide - Learn Your Way Around
  • 2024-2025 Calendar Dates
  • 2025-2026 Calendar Dates
  • See Something Say Something Reporting

Schools

  • McFarland Primary School (4K-2)
  • Waubesa Intermediate (3-5)
  • Indian Mound Middle (6-8)
  • McFarland High (9-12)
  • Online Virtual Charter Schools
District Home

Important Links

  • Canvas Login
  • District Calendar
  • Lunch Menus
  • Infinite Campus - Student/Parent
  • Infinite Campus - Staff
  • Staff Directory

Variables

McFarland High (9-12)

    • McFarland High School
    • Academic & Career Planning (ACP)
      • Youth Apprenticeship
    • Athletic & Activity Code of Conduct
    • Canvas Login
    • Clubs
    • Communications
    • Course Supply List
    • Daily Announcements
    • Daily Schedules
    • Family Handbook
    • Grading Handbook
    • Graduation Information
    • Library Media Services
    • Music
    • Office Staff
    • PBIS
    • Portfolio Resources
    • Progressive Behavior Response Plan
    • Report Suspicious Activity
    • School To Career
    • Spartan Headquarters
    • Special Education
    • Sports
      • Boys Teams
        • Baseball
        • Basketball
        • Football
        • Golf
        • Hockey
        • Lacrosse
        • Soccer
        • Swimming
        • Tennis
      • Coed Teams
        • Cross Country
        • Track & Field
        • Wrestling
      • Girls Teams
        • Basketball
        • Dance
        • Golf
        • Hockey
        • Lacrosse
        • Soccer
        • Softball
        • Swimming
        • Tennis
        • Volleyball
      • 24-25 Sport Registration-Athletic Code Video
      • Athletic & Activity Code of Conduct
      • Concussion & Sudden Cardiac Arrest Info
      • Infinite Campus Sport Registration Info Sheet
      • Parent Resources
      • Parent Transportation Form
      • Spartan Sport Sponsors
      • Uniform Care Info
      • WIAA Medical Eligibility Form
    • Staff Directory
    • Student Services
      • Transcript Request (former students)
    • Xello - Student
    • Web Design 1
      • Class Lessons
        • XHTML Tutorial
        • CSS Tutorial
        • Form Tutorial
        • Graphics
        • Dreamweaver
        • QuickMenu
        • Joomla!
      • Assignments
        • Site 1: Biography
        • Site 2: Fan Club
        • Site 3: Mixed Media
        • Site 4: Joomla!
      • Student Samples
        • Biography Sites
        • Fan Club Sites
        • Mixed Media Sites
        • Joomla! Sites
      • Helpful Sites
        • XHTML Help
        • CSS Help
        • Validation
        • QuickMenu
        • Joomla! Help
    • Web Design 2
      • Class Lessons
        • JavaScript Tutorial
        • PHP Tutorial
        • MySQL Tutorial
        • Admin - CMS
      • Assignments
        • Using JavaScript
        • For the Birds
      • Helpful Sites
        • JavaScript Tutorials
        • RegExp Help
        • Web Page Validation
    • Programming 1
      • Class Lessons
        • CLASS SET-UP
        • Logic Test
        • Class Preparation
        • Using BlueJ
        • --------------------
        • SET 1 LESSONS:
        • Printing
        • Variables
        • User Input
        • Random Number
        • Arithmetic
        • --------------------
        • SET 2 LESSONS:
        • If
        • Switch
        • --------------------
        • SET 3 LESSONS:
        • Looping
        • --------------------
        • SET 4-5 LESSONS:
        • Arrays
        • --------------------
        • SET 6 LESSONS:
        • String Manipulation
      • Problem Sets
        • Set 1: Basic Skills
        • Set 2: If & Switch
        • Set 3: Loops
        • Project: Craps
        • Set 4: Single Array
        • Set 5: Double Array
        • Set 6: Strings
      • Solution Sets
        • Problem Set 1
        • Problem Set 2
        • Problem Set 3
        • Problem Set 4
        • Problem Set 5
        • Problem Set 6
      • Helpful Sites
    • Programming 2
      • Class Lessons
        • Using BlueJ
        • What is an Object?
        • What is a Class?
        • GUI Programming
      • Problem Sets
        • Set 1 - Shapes
        • Set 2 - Exercises
        • Set 3 - Exercises
        • Set 4 - Exercises
        • Project - Adding
        • Set 5 - GUI by Hand
        • Project - NetBeans
        • Set 6 - NetBeans
        • Project - Life
        • Project - Slide Puzzle
        • Project - Matching
      • Solution Sets
        • Problem Set 1 (none)
        • Problem Set 2 (none)
        • Problem Set 3 (none)
        • Problem Set 4
    • McFarland High School
    • Academic & Career Planning (ACP)
      • Youth Apprenticeship
    • Athletic & Activity Code of Conduct
    • Canvas Login
    • Clubs
    • Communications
    • Course Supply List
    • Daily Announcements
    • Daily Schedules
    • Family Handbook
    • Grading Handbook
    • Graduation Information
    • Library Media Services
    • Music
    • Office Staff
    • PBIS
    • Portfolio Resources
    • Progressive Behavior Response Plan
    • Report Suspicious Activity
    • School To Career
    • Spartan Headquarters
    • Special Education
    • Sports
      • Boys Teams
        • Baseball
        • Basketball
        • Football
        • Golf
        • Hockey
        • Lacrosse
        • Soccer
        • Swimming
        • Tennis
      • Coed Teams
        • Cross Country
        • Track & Field
        • Wrestling
      • Girls Teams
        • Basketball
        • Dance
        • Golf
        • Hockey
        • Lacrosse
        • Soccer
        • Softball
        • Swimming
        • Tennis
        • Volleyball
      • 24-25 Sport Registration-Athletic Code Video
      • Athletic & Activity Code of Conduct
      • Concussion & Sudden Cardiac Arrest Info
      • Infinite Campus Sport Registration Info Sheet
      • Parent Resources
      • Parent Transportation Form
      • Spartan Sport Sponsors
      • Uniform Care Info
      • WIAA Medical Eligibility Form
    • Staff Directory
    • Student Services
      • Transcript Request (former students)
    • Xello - Student
    • Web Design 1
      • Class Lessons
        • XHTML Tutorial
        • CSS Tutorial
        • Form Tutorial
        • Graphics
        • Dreamweaver
        • QuickMenu
        • Joomla!
      • Assignments
        • Site 1: Biography
        • Site 2: Fan Club
        • Site 3: Mixed Media
        • Site 4: Joomla!
      • Student Samples
        • Biography Sites
        • Fan Club Sites
        • Mixed Media Sites
        • Joomla! Sites
      • Helpful Sites
        • XHTML Help
        • CSS Help
        • Validation
        • QuickMenu
        • Joomla! Help
    • Web Design 2
      • Class Lessons
        • JavaScript Tutorial
        • PHP Tutorial
        • MySQL Tutorial
        • Admin - CMS
      • Assignments
        • Using JavaScript
        • For the Birds
      • Helpful Sites
        • JavaScript Tutorials
        • RegExp Help
        • Web Page Validation
    • Programming 1
      • Class Lessons
        • CLASS SET-UP
        • Logic Test
        • Class Preparation
        • Using BlueJ
        • --------------------
        • SET 1 LESSONS:
        • Printing
        • Variables
        • User Input
        • Random Number
        • Arithmetic
        • --------------------
        • SET 2 LESSONS:
        • If
        • Switch
        • --------------------
        • SET 3 LESSONS:
        • Looping
        • --------------------
        • SET 4-5 LESSONS:
        • Arrays
        • --------------------
        • SET 6 LESSONS:
        • String Manipulation
      • Problem Sets
        • Set 1: Basic Skills
        • Set 2: If & Switch
        • Set 3: Loops
        • Project: Craps
        • Set 4: Single Array
        • Set 5: Double Array
        • Set 6: Strings
      • Solution Sets
        • Problem Set 1
        • Problem Set 2
        • Problem Set 3
        • Problem Set 4
        • Problem Set 5
        • Problem Set 6
      • Helpful Sites
    • Programming 2
      • Class Lessons
        • Using BlueJ
        • What is an Object?
        • What is a Class?
        • GUI Programming
      • Problem Sets
        • Set 1 - Shapes
        • Set 2 - Exercises
        • Set 3 - Exercises
        • Set 4 - Exercises
        • Project - Adding
        • Set 5 - GUI by Hand
        • Project - NetBeans
        • Set 6 - NetBeans
        • Project - Life
        • Project - Slide Puzzle
        • Project - Matching
      • Solution Sets
        • Problem Set 1 (none)
        • Problem Set 2 (none)
        • Problem Set 3 (none)
        • Problem Set 4

What Are Variables?

+
-

 

Variables allow data to be stored. The data can then be used throughout the program and changed as needed. There are a number of types of variables. For example there is a Char variable that can store one character of data. An int variable can store one integer, or whole number. Except for very simple programs, all programs use variables.

When a variable is created in a Java program the action that is taking place in the computer is that it reserves some room in the computer's memory to hold the data.

To use a variable in Java (and most computer languages) you must first declare the variable. In other words, you must write some code that tells the computer what data type of variable you are creating and then the name (or identifier) of the variable. The name of the variable has to follow a set of rules.

Variable naming rules:

  • may not start with a number
  • must begin with a letter, dollar sign, or an underscore
  • cannot contain punctuation
  • cannot have a space
  • are case sensitive (so car and Car and CAR would be three different variable names)
  • can use upper and lower case letters, digits, dollar sign ($) and the underscore ( _ ) character
  • keywords cannot be used as identifiers


Declaring an integer variable named totalScore would take the form: int totalScore;

Declaring a String variable named firstName would take the form: String firstName;


Variables should be declared at the top of the code, not dispersed throughout the code. Although this is not a technical requirement, it does make reading the code much easier and if it was necessary to make a change in the variable it is muach easier to locate.

A typical program with variables would look like:

class myProgram
{
  public void getInfo()
   {
    int temperatureF; //declares an integer variable named temperatureF
    String userName; //declares a String variable named userName

    ... code for the rest of the program goes here ...

   }
}

 


 

String

+
-

 

String variables are used to store text. For example, in a game you would want to store the name of the player. Strings are sequences of characters (i.e. letters, punctuation and spaces).

Sample String variables:

String firstName = "Jim";
String book_title = "Gone with the Wind";
String my_sentence = "This is a rather short sentence.";


Important Notice: You may have noted that String is capitalized while most variable types are lowercase. Some variable types are 'primitive' while other are not. It is not important that you understand the differences to do the work in this class. If you'd like to find out more about this topic there are plenty of resources available on the Internet.
 



For each of the Programming 1 lessons you are strongly encouraged to view and play around with the sample code provided in the BlueJ Java Student Samples folder.

Open BlueJ and choose Open Project from the Project menu. Navigate to your Programming 1 folder on the I: drive and open the BlueJ Java Student Samples folder. Open the project named first.

 

 

Lesson Example: Project first, Class StringVariables, methods name() and another_name()

  • Right-click on the Class named StringVariables and select new StringVariables()
  • Right-click on the red rectangle and choose the method named name()
  • Right-click on the red rectangle and choose the method named another_name()

 

Code of name() method: (Important! Read the comments in the code in order to better understand the code)

void name()
  {
    String name;
    name = "Bob";
    System.out.println(name);
    System.out.println("Hi " + name); //notice that if text (literals) are to be

                                      //combined with variables in a print or
                                      //println statement they must be separated 
                                      //by a +

    System.out.println("Hi " + name + " you are a fine person.");   

                                 
  }

 

Code of another_name() method: (Important! Read the comments in the code in order to better understand the code)

void another_name()
  {
    //notice that you can assign a value to the variable when declaring the variable
    //this called initializing the variable because you are giving it its initial,
    //or
first value sometimes a variable must be initialized before the program
    //will compile
    String name="Sue";   
    System.out.println("Hi " + name);
  }

 

 

 


 

char

+
-

 

char variables are used to store individual characters, not a long string of characters like the String variable.

Sample char variables:

char oneLetter = 's';
char oneDigit = '4';
char oneChar = '&';


Important Note: char variables must be enclosed in single quotes, not double quotes like the String variable.



For each of the Programming 1 lessons you are strongly encouraged to view and play around with the sample code provided in the BlueJ Java Student Samples folder.

Open BlueJ and choose Open Project from the Project menu. Navigate to your Programming 1 folder on the I: drive and open the BlueJ Java Student Samples folder. Open the project named first.

 

 

Lesson Example: Project first, Class charVariables, method charVariable()

  • Right-click on the Class named charVariables and select new charVariable()
  • Right-click on the red rectangle and choose the method named charVariable()

Code of charVariable() method:

class charVariables
{

  void charVariable()
    {
        char firstCharacter ='J';
        char secondCharacter = '@';
       
        System.out.println("The first character is " + firstCharacter + ".");
        System.out.println("The second character is " + secondCharacter + ".");
    }
}

 

 


 

int

+
-

 

int variables are used to store an integer (whole number) value. You will not use int variables a lot but they are very useful for certain tasks. int variables are used in 'whole math' problems. For example, in whole math 10/3 = 3 with a remainder of 1, not 3.3333 (to infinity and beyond).

Sample int variables:

int size = 4;
int code = 42;
int inches = 12;

 


For each of the Programming 1 lessons you are strongly encouraged to view and play around with the sample code provided in the BlueJ Java Student Samples folder.

Open BlueJ and choose Open Project from the Project menu. Navigate to your Programming 1 folder on the I: drive and open the BlueJ Java Student Samples folder. Open the project named first.

 

 

Lesson Example: Project first, Class intVariables, methods usingInt1(), usingInt2() and integerDivision()

  • Right-click on the Class named intVariables and select new intVariables()
  • Right-click on the red rectangle and choose the method named usingInt1()
  • Right-click on the red rectangle and choose the method named usingInt2()
  • Right-click on the red rectangle and choose the method named integerDivision()

 

Code for usingInt1():

void usingInt1()
    {
        int x;
        int y;
        x=5;
        y=6;
        System.out.println("The numbers are " + x + " and " + y);
    }

 

Code for usingInt2():

void usingInt2()
    {
        int x,y,z;
        x=5;
        y=6;
        z=x+y;
        System.out.println(x + "+" + y + "=" + z);
        System.out.println(x + "+" + y + "=" + (x+y));
    }

   

Code for integerDivision():

void integerDivision()
    {
        int whole,remainder,x,y;
        x=17;
        y=3;
        whole = x / y;
        remainder = x % y;
        System.out.println(x + " divided by " + y + "=" + whole +

                           " with a remainder of " + remainder);
    }

 

 


 

double

+
-

 

double variables are used to store decimal numbers. Most numbers used in a program are of this type.

Sample double variables:

double loan_rate = .09;
double length = 12.55;
double weight = 178.9;

Special Notice: when using decimal numbers in a calculation the results will usually have a large number of decimal places. The following code samples illustrate a method to format the output to an appropriate number of decimal places.
 

Format output to three decimal places: miles = Math.round(miles*1000.0)/1000.0;

Format output to two decimal places: miles = Math.round(miles*100.0)/100.0;

Format output to one decimal place: miles = Math.round(miles*10.0)/10.0;

 



 

For each of the Programming 1 lessons you are strongly encouraged to view and play around with the sample code provided in the BlueJ Java Student Samples folder.

Open BlueJ and choose Open Project from the Project menu. Navigate to your Programming 1 folder on the I: drive and open the BlueJ Java Student Samples folder. Open the project named first.

 

 

 

Lesson Example: Project first, Class doubleVariables, methods usingDouble and doubleDivision

  • Right-click on the Class named doubleVariables and select new doubleVariables()
  • Right-click on the red rectangle and choose the method named usingDouble()
  • Right-click on the red rectangle and choose the method named doubleDivision()

 

Code for method usingDouble():

    void usingDouble()
    {
        double x,y,z;
        x=3.2;
        y=8.51;
        z=x+y;
        System.out.println(x + " + " + y + " = " + z);
    }

 

Code for doubleDivision():

    void doubleDivision()
    {
        double x,y,z;
        x=17;
        y=3;
        z=x/y;
        System.out.println(x + "/" + y + " = " + z);
    }

 

 


 

boolean

+
-

 

boolean variables can store the value of true or false. There are many instances where boolean variables are useful. For example, if a score in a game is at the amount needed to win then the computer can compare the score to the amount needed to win and see that it is true, the score is the same as the amount to win.

Sample boolean variables:

boolean readyToGo = true;
boolean timeIsUp = false;
boolean playAgain = true;

 



For each of the Programming 1 lessons you are strongly encouraged to view and play around with the sample code provided in the BlueJ Java Student Samples folder.

Open BlueJ and choose Open Project from the Project menu. Navigate to your Programming 1 folder on the I: drive and open the BlueJ Java Student Samples folder. Open the project named first.

 

 

Lesson Example: Project first, Class booleanVariables, methods usingBoolean() and usingBoolean2()

  • Right-click on the Class named booleanVariables and select new booleanVariables()
  • Right-click on the red rectangle and choose the method named usingBoolean()
  • Right-click on the red rectangle and choose the method named doubleBoolean2()

 

Code for usingBoolean():

  void usingBoolean()
    {
        boolean warm = false;
       
        if(warm==true)//can be shortened to if(warm) because true is default value
          System.out.println("It sure is warm in here.");
        else
          System.out.println("It sure is cool in here.");
    }

 

Code for usingBoolean2():

  void usingBoolean2()
    {
        boolean warm = false;
       
        if(!warm)//the ! stand for the word 'not', so the line reads:

                 //if not warm is true
          System.out.println("It sure is cool in here.");
        else
          System.out.println("It sure is warm in here.");
    }

 

 


 

McFarland School District Home

McFarland School District

Grades: 9 - 12

Contact Information

  • McFarland High School (9-12)

    5103 Farwell Street
    McFarland, WI 53558
  • Phone

    608 838-3166
  • Fax

    608 838-4562

Social Media

  • McFarland School District Social Facebook
  • McFarland School District Social Instagram
McFarland School District Mark

© 2025 McFarland School District

  • Non-Discrimination Statement
CMS4Schools