Lucky Cat Tutoring Services

Arrays 01
November 3, 2009, 4:44 pm
Filed under: Class Notes, Java | Tags: , , , , , , ,

–Primitive variables are designs to hold only one value at a time
–allows to create collection of like indexed values
–can store any type of data but only one type at a time
–List of data elements

Creating Arrays
–An array is an object so it needs to be referenced. Then create array and assign address

int[]nameofarray=new int [INTEGER VALUE]

Integer value can be a variable, a constant etc but always must be INT.
–Whatever data type is stored in the array determines how it is initialized. If it’s created as an INT all values start at 0.
–may be of any type (floats, car, long, double etc)

ARRAY SIZE: must be a non negative number. It may be a literal, a constant, or avariable
ex: final int ARRAY_SIZE=6
int[] numbers=new int[ARRAY_SIZE]
–Once created the size is fixed and cannot change!!

–The first element is ALWAYS INDEX 0. The last element in the array is always the size or length -1

In an array with 6 indexes. The first one is index0, the last one is index5

Calling an index:
arrayname[indexnumber]= new value //assigning variables to be held in the index

An array is accessed by:
–The reference name
–the subscript [] which declares what to access

Can be treated like any other variable of the same type.
Continue reading


Return Method Example
October 20, 2009, 4:08 pm
Filed under: Uncategorized | Tags: , , , , , ,

Here’s an example of a method that returns the smallest number out of a set of three entered by the user:
Continue reading

CIT 111: Booleans & Other Primitive Data Types
September 1, 2009, 3:31 pm
Filed under: Uncategorized | Tags: , ,

Booleans: Can hold true or false, can be assigned any way that we want them, as long as the expression evaluates to “true or false”.


// A program for demonstrating boolean variables

public class TrueFalse
public static void main(String[] args)
boolean bool;
int a=18, b=12;
bool = true;
bool = false;
bool = a > b;
if (bool)
{System.out.println(“‘a’ is larger than ‘b'”);

Should come out to say:

‘a’ is larger than ‘b’

Process completed.

CHARS: are letter based only; can only hold a single character.

// This program demonstrates the char data type.

public class Letters
public static void main(String[] args)
char letter;

letter = ‘A’;
letter = ‘B’;

-Errors occur when more than one character is used. Char can only use ONE.

-Double quotes “” around the single character makes it the wrong data type. Anything with “” is a STRING not a CHAR!! Single quotes must always be used

Chars and Integer relationships:
Letters can be assigned using numeric value for a letter in Java 6.

CIT 111 Java 101 week 2
August 25, 2009, 4:36 pm
Filed under: Class Notes, Java | Tags: , , ,

Time for more notes from D Smith’s CIT 111 class at CCAC.

A quick review:
–Classs can stack
–You can only have 1 main class
–You can have as many “Methods” in your class as you want
–All you need to get a program to run at all is a basic skeleton:

/*This is where comments go
public class nameOfProgram
        public static void main(String[] args)



Lets make a little program to draw a star pattern using last week’s lesson:

public class StarProgram
 { public static void main(String []args)
   System.out.println(”    *    “);
   System.out.println(“*       *”);
   System.out.println(”    *   “);
   System.out.println(”    *    “);
   System.out.println(”   ***   “);
   System.out.println(”  *****  “);
   System.out.println(” ******* “);
   System.out.println(”  *****  “);
   System.out.println(”   ***   “);
   System.out.println(”    *    “);
 } // ends the class and program

This displays a little star pattern like old school “Hi I’m drawing with emoticons” postings from the dark ages of the internet.  Don’t like how it looks? No need to delete a line of code:

Just turn whatever line that bothers you into a comment by dropping a “//” in front; great for debugging.


Learning about initializing variables

–if you plan to use a variable you need to declare it

–Variable can just be declared: ex int hours
–Assign set amount: ex int hours = 40;

int (INTEGERS) ex 7, 27, whole numbers
—Byte: 1 byte of memory
—Short: 2 bytes
—Long: 8 bytes. All LONGS must have the suffix “L” at the end or it will be output as an integer and not a long
double (FLOATING POINT) ex 7.1, 27.3 decimals
public class IntegerVariables
public static void main(String[] args)
int checking; // Declare an int variable named checking.
byte miles; // Declare a byte variable named miles.
short minutes; // Declare a short variable named minutes.
long days; // Declare a long variable named days.

//assignments to the data types, not redeclared
checking = -20;
miles = 105;
minutes = 120;
days = 185000L; //make sure it stays long
// int years = days / 365; mixed data types don’t work
int years = (int)days / 365; //years must be long; can’t fit 8 bytes of stuff in 4 byte box. Use explicite casting
Continue reading

Java programming 101 week 1
August 20, 2009, 4:19 pm
Filed under: Class Notes | Tags: , ,

I’m going to post all my notes for CIT 111 up here on the learning blog for those who either can’t take notes, didn’t, or like me in normal class can’t read them. Lets start with week 1 in Java Programming with D. Smith at CCAC

Basic programs for Java: jdk-6u2-windows-i586-p (library of java classes), jcreate400.
Resource Sites:
– Site for java Developers download resources for Java SE Java Tutorials home

I: Intro to Java
–All classes needed to program can be found in the Java Platform documentation, found in the links to the right.

I2: Starting with J Creator LE
–The program may look familiar as it’s built like the average windows program.

  1. Go to NEW>FILE>Empty java file
  2. When naming your file, the FILE NAME should be the same name as the CLASS NAME
  3. FILE NAME must ALWAYS begin with an uppercase letter: EX (
  4. CONFIGURE>JAVA>Show line numbers


  1. Every time you write a program, you need to have comments. Comments keep things organized, remind what parts of code do,
  2. // = comment start (will show up green)
  3. /* =block comment. Lets you write a whole paragraph of coments without having to do // for every line
  4. {} = Determines where a class begins and ends like < > in HTML. Everything that is in the class (EX: public class LuckyCat)

EX so far:


/*  LuckyCat
 *  CIT 111 AC02
 *  08-20-09
 *  This is an in class toy
 public class LuckyCat //class declaration
           public static void main(String [] args) //method declaration

 }// ends class

Continue reading