Tuesday, March 31, 2015
Wednesday, February 11, 2015
Headfirst Java: Chapter 4
Classes: What are they? What do they do?
- Classes are structures of code that can tell what exactly an object knows and or does
- Things, or data that an object knows are refered to as "Instance Variables"
- "Methods" are the things a specific object does
- Methods use Instance Variables explicitly to differentiate between various objects.
- Methods can have parameters like functions in Python.
- Methods in Java can have several parameters.
- When using parameters they must match the variable type IN the method. (ex. If i use a float for a parameter and call it an int inside of the method, it wont compile)
- Methods must return somthing unless it is explicity stated it wont with a "void" command.
Activities:
- The first activity was relatively easy to decipher, side A being correctly coded, will output 42 84. Section B was moderately dificult however. The only error i spotted in the code was "void getTime()". The only reason this was flawed because it wasnt declaired as a string variable, so Java would not be able to read it correctly. It also seemed worth to note that GET methods must return a value of some sort.
- This section was hard for me to keep track of becasue the modification of many variables in quick sucession. I ended up sorting through it one line at a time plugging in each of the values to figure out Java's output for all of the commands.
Friday, January 30, 2015
Random Code Snipit
Since Chapter three was dedicated to making sure you knew what variables are, I decided that I would make a code that uses several class variables, involving strings and integers. Here is the code:
The code is designed to loop 5 times untill a grumpy farmer gets sick of hearing his dogs bark! after that he gets fed up and yells for them to be quiet! He needs some earplugs!
The code is designed to loop 5 times untill a grumpy farmer gets sick of hearing his dogs bark! after that he gets fed up and yells for them to be quiet! He needs some earplugs!
Thursday, January 22, 2015
Chapter 3: Variables (Fixed)
(above is the result of compiling the dog code)
Fundementals of Variables in Java:
- There are several variable types in Java:
Float
Int
Double
Bool
Byte
Short
Long
Char
- Float's use decimal values (ex: .25, .111, .8)
- Int or Intiger uses full number values (ex: 1, 5, 25)
- Doubles combine BOTH Float and Int values (ex: 1.25, 3.49, 6.64)
- Bool or Boolean Variables use either True OR False (ex: While True, do this...)
- Byte variables are 8-Bit variables, used to save memory in large arrays (ex: byte a = 100 , byte b = -50)
- Small variables are 16-Bit and used to help conserve data. Its Minimum and Max value are -32,768, and 32,768
- Long variables are 64-Bit and are also used to conserve data. Its minimum and Max values are - 2,147,483,648 and 2,147,483,648
- A char variable is a variable that uses a charector (ex. A, B, C, D)
Thursday, January 15, 2015
Chapter Two: A Trip to Objectville
This chapter really emphesized Javas features as an object oriented programming language. Most of the reading was a story about two programmers assigned to accomplish a task. One programmer prefered to use procedureal based program, and the other liked OO. In the end the OO programmer had the advantage because he had the ability to program without having to touch a single piece of previously tested code, whereas a procedural programmer would have to rewrite the whole code to accomidate for the new specifications.
Later on you also begin to read that all of Java code is defined as a class. One analogy that the book made to the setup is that a Class is to and Object, as a Recipee is to a Cookie. Objects can store information, and also execute tasks. Things objects know about themselves are known as instance variables. These variables represent the status of an object. Like functions in Python, things objects do are called Methods. Different classes can inherit conditions from other ones.
Friday, January 9, 2015
Headfirst Java: Chapter One
Reading chapter 1 of the book, Headfirst Java, has taught me much about the setup and structure of Java programming. Compared to Python, Java is organized much differently. Java is setup in the sequence of Source Files; within those files there are class files, and again within those class files there are Methods, and within methods there are statements.
Python, is very different in the organization. In python there are the Source files, and class files. The difference is in the class files, is that they aren't organized in methods. There are loops, and functions. Loops only active while the code is being read, and functions only activate when typed into the command prompt. Within either loops or functions, there are also statements, however the syntax also tends to be much shorter than Java's.
For example, to get a program to state a string, all you need to do is use the statement: print "Your statement here". In java you have to use the statement: system.out.print "Your statement here." Below is a snip-it of the code I worked on to help get to learn the syntax and structure.
Python, is very different in the organization. In python there are the Source files, and class files. The difference is in the class files, is that they aren't organized in methods. There are loops, and functions. Loops only active while the code is being read, and functions only activate when typed into the command prompt. Within either loops or functions, there are also statements, however the syntax also tends to be much shorter than Java's.
For example, to get a program to state a string, all you need to do is use the statement: print "Your statement here". In java you have to use the statement: system.out.print "Your statement here." Below is a snip-it of the code I worked on to help get to learn the syntax and structure.
Subscribe to:
Posts (Atom)