Introduction to Programming with examples

This post is about my first 3 lesson into Java programming all 3 was 2 hours long, however I have just joined all of what I have learnt into 1 blog to make it easier. At the start I of the lesson I had strong remorse about programming however as the lesson went on I started to become more and more comfortable with programming.

The thing that I learnt and really stuck with me and helped me was the list below. This helped me as it put my worries about programming behind me.

  • You don’t have to be good at math’s
  • You don’t need to know the answers, its about finding them out
  • Java and JavaScript are not the same thing – they are both C based programming
  • Programming IS extremely creative
  • Programming is about constantly solving puzzles
  • Programming is HARD

Live Example’s

While learning some of the key words, we created a few fun games and examples. Theses are below.

Jave01

In this example I created a basic square and it the programs set-up. Theses are the very basics in creating a program as I have used a set-up function to create the size and colour of the program and I have also used a draw command.

Screen Shot 2014-10-16 at 16.28.48

I then went ahead and created a number of shapes which will reset once the mouse was clicked. I added a cap on the amount drawn which is 10. In order to do this I had to use a void for each of the setups. I also had to make it so when the mouse is clicked the int called numberDrawn was reset back to 10. Finally I had to use a random() function to randomly place the shapes across the scene.

Screen Shot 2014-10-16 at 16.32.50

The final example I took the random generating square and capped it to 1 square however this time I used an array to random change the colour every time the mouse is clicked swell as moving. This was done by using a random number float and converted it to an in by using these code here “float f = random(0, 6;
int i = int(f);
println(f + ” : ” + i);” This code will generate a number between 0 and 5, then convert it to an int called I. This int was then called to the fill to the fill “fill(randomColor[i]);”. So now the random number generated is converted to a whole number then called to the array with the random colours in called “randomColour”.

Below is a long list of key terms and functions which I used to create the examples above.

  • IDE- integrated development environment – the program that we program in
  • Variables – building blocks of programming – stores information – give it a name to reference in the code
  • Parentheses ()
  • Functions – Is a set of commands that we call upon – a group of instructions make up a method
  • Methods –  The same concept of function but its not linked to a class
  • Class- is something eg person
  • Instant- every time we make a person we make an instance of that class
  • Data type- bolen (true or false)
  • Loop- a looped event that will loop until something is meet like testing for something
  • Compeller- This will translate the code into machine code so the program can run
  • Condition statement- We ask for some and want a true or false back
  • OOP- Object orientated programing- based around the idea of programming around an object, based on an idea of creating a world and relate programing at any time no matter what order in the code is so its not liner programming which goes from top to bottom.
  • Camel Casing- first word lower case and instead of a space is a capital thisIsAExample

Formatting

if (newScore > topScore)

printin(“This is a new top score”)

Always code as if the guy who ends up maintaining your code will be violent and knows where you live

 What is in an IDE 

Code writing area – where you write the code

Compiler – Runs the program

Log window – will print errors and other stuff

Code (Java)   – IDE used Processing

println(“This will print to the log”);      print to log

size(xxx, yyy);         Screen size

background(000, 000, 000);     background colour

rect(X, Y, width, hieght);        Creates a rectantle

ellipse(postionX, postionY, Width, Height);  – mouseX, mouseY will draw follow the mouse-    draws a circle

fill(000, 000, 000);        Will fill in objects

void= don’t expect something back, just run the instructions and not receive information

void draw = constantly loops and will draw

void mouseClicked = will carry out the instruction when mouse clicked

>/< – more than and less than

x++; – add 1

x–; – take away 1

|| – Or

&& – And

!= not equals to

= – assignment

== – comparison

=== – identical to

// – comment

/* – code here – */  – comment out sections of code at once

if (conditional statement) {

instruction

} else {

instruction

}

Create a function 

functionName()  {

add instructions here

}

 Page Break 

Int – int name(no spaces) = number; This is a decliration

 Loops 

Two types of loops – for and while

for(int I=0<10; I++){

//do whatever we want here

}

variable – condition – iteration

 stroke cap 

strokeCap() – sets the style for how the line ending are drawn – square, project

Stroke join 

strokeJoin() – sets the style for how line are joined

Stroke weight 

strokeWeight – sets the thickness of the stroke line

Opacity fill(150, 140, 140, transpacany);

Array

Array numbers 

int x = 10;

int [] myNumbers = {23, 56, 79, 173, 45};

println(myNumbers);

println(myNumbers[2]);

Array Colours 

color[] myColors = {#00FF5B, #BD09D6, #D6AA09};

size(600, 300);

fill(myColors[2]);

rect(60, 60, 60, 60);

 

Advertisements

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