Lucky Cat Tutoring Services


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:
–Java.sun.com: Site for java Developers
http://java.sun.com/javase/downloads/index.jsp: download resources for Java SE
http://java.sun.com/docs/books/tutorial/: 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.
—A: MAKING A NEW PROJECT

  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 (LuckyCat.java)
  4. CONFIGURE>JAVA>Show line numbers

–B: STARTING THE PROJECT

  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:

//PROGRAM TITLE

/*  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

VOCABULARY BREAK!

METHOD DECLARATION: system needs to find the main method so it must be “public”.  “Static” says this class has ONE main method. “Void” says that the method doesn’t return a value.

TEXT STRING: any line of text inside ” “

Now…build the file. One of two things can happen:

1) Process complete: congrats! it works

2) if it doesn’t say Process Complete: congrats, you just completed your first syntax error ^.^ Remember cleanliness is next to godliness in programs. Don’t worry, Java will tell you what’s wrong. Now go fix it

FIXING ERRORS:

Fix them one at a time. Fix, then build and see if it worked.  Don’t make lots of fixes then run it because you wont’ be able to tell what was really broken.

Find something that works: Sometimes you need to copy a bit of code from an example that you know will work.

When you built it, what happened?

Java made a “byte code file”. This lets Java run by itself using Java virtual machine. When you write the program at school, then take the program home, it can run itself by itself. Of course you’ll never want to actually work with byte code which is computer language. This is why we use a programming language.

————————–

Now lets write a Statement. A statement is a command to make the computer do something. ALL STATEMENTS must end in a “;”

EX: System.out.println(“Cat form iz 4 fight!”);

Your final toy program should look like this in code:
//PROGRAM TITLE

/* 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

{
System.out.println(“Cat form iz 4 fight!”);

}
}// ends class

(keep in mind that wordpress does mangle code tabs and such.)

Once you have saved the file out you should get two files: a program and a code

ex: LuckyCat.java, LuckyCat.class

.java is the program, .class is the byte code

Advertisements

Leave a Comment so far
Leave a comment



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s



%d bloggers like this: