onsdag 13 juni 2012
Skapa jar-fil i eclipse
Föreläsning 26 handlade om hur du skapar en jar-fil i eclipse och om "standardjava", dvs hur man kodar om man inte har tillgång till acm-biblioteket. Han gick bland annat igenom main, vilket gav mig en härlig känsla av att det här kan jag ju redan.
Etiketter:
Stanford Uni
måndag 11 juni 2012
Thread
Föreläsning 25.
Thread - att göra många saker, som du upplever att du gör, samtidigt. Ex kollar mailen, surfar, kollar play.
Multithreading pratade han också om. Hittade dock den här sidan som tar upp det mer ingående.
Thread - att göra många saker, som du upplever att du gör, samtidigt. Ex kollar mailen, surfar, kollar play.
Multithreading pratade han också om. Hittade dock den här sidan som tar upp det mer ingående.
Etiketter:
Stanford Uni
Struktur
Föreläsning 24.
Denna gång går Mehran igenom ett programs struktur, hur du ska tänka när du bygger ditt program.
Principles:
nouns (substantiv) - classes
verbs - methods (associated with your classes)
unique identifier ex. Stanford Uni IDnr, ISBN nr, Artist + album + song
Design
collection of objects
Ex a musicstore called FlyTunes
add Songs
add Albums
class Song: name - String
band - String
price - Double
Think about: What's gonna stay static and what's gonna change?
Denna gång går Mehran igenom ett programs struktur, hur du ska tänka när du bygger ditt program.
Principles:
nouns (substantiv) - classes
verbs - methods (associated with your classes)
unique identifier ex. Stanford Uni IDnr, ISBN nr, Artist + album + song
Design
collection of objects
Ex a musicstore called FlyTunes
add Songs
add Albums
class Song: name - String
band - String
price - Double
Think about: What's gonna stay static and what's gonna change?
Etiketter:
Stanford Uni
fredag 8 juni 2012
Searching and sorting
Lecture 23.
Searching: Linear and Binary
Finding a particular element in an array or some other kind of sequence. The element is called a key.
Linear Search
- timeconsuming
private int linearSearch (int key, int[] array){
for (int i = 0; i < array.length; i++) {
if (key == array[i]) return i;
}
return -1;
}
Binary search
Ask if the nr is higher/lower than the middle nr. Then ask again and again...
The idea of the binary search is the fact that area code array is an ascending order makes it possible to find a particular value much more efficiently. The key insight is that you get more information by starting at the middle element than you do by starting at the beginning.
private int binarySearch(int key){
int kh = 0;
int lh = display.length() -1;
while ( lh <= rh){
int mid = (lh+rh) / 2;
if (key == disp.get(mid)) return mid;
if (key < disp.get(mid)){
rh = mid -1; //to move from the midpoint
}
else{
lh = mid +1;
}
Sorting
Selection sort and Radix sort algorithm
}
return -1;
}
Searching: Linear and Binary
Finding a particular element in an array or some other kind of sequence. The element is called a key.
Linear Search
- timeconsuming
private int linearSearch (int key, int[] array){
for (int i = 0; i < array.length; i++) {
if (key == array[i]) return i;
}
return -1;
}
Binary search
Ask if the nr is higher/lower than the middle nr. Then ask again and again...
The idea of the binary search is the fact that area code array is an ascending order makes it possible to find a particular value much more efficiently. The key insight is that you get more information by starting at the middle element than you do by starting at the beginning.
private int binarySearch(int key){
int kh = 0;
int lh = display.length() -1;
while ( lh <= rh){
int mid = (lh+rh) / 2;
if (key == disp.get(mid)) return mid;
if (key < disp.get(mid)){
rh = mid -1; //to move from the midpoint
}
else{
lh = mid +1;
}
Sorting
Selection sort and Radix sort algorithm
}
return -1;
}
Etiketter:
Java kod,
Stanford Uni
torsdag 7 juni 2012
Blogg
En blogg för nybörjare med vad det verkar, bra och enkla förklaringar och en hel del kod. Me like! A Beginning Programmer's guide to Java.
Etiketter:
Bra sidor
Using Graphics
tisdag 5 juni 2012
Components and containers
Lecture 22.
Mehran talks shortly about Components and containers berfore he goes into a codefrenzy :-)
Components is anything that can appear in a window and containers contains other components. Think of a bag that contains (components and) another bag. Bag in a bag in a...
Mehran talks shortly about Components and containers berfore he goes into a codefrenzy :-)
Components is anything that can appear in a window and containers contains other components. Think of a bag that contains (components and) another bag. Bag in a bag in a...
Etiketter:
Stanford Uni
Text Areas
Den här förmiddagen roar jag mig med den här sidan; How to use Text Areas.
Tänkte lägga upp koden men internet strular på den andra datorn (ja jag sitter med två datorer samtidigt, hehe).
Tänkte lägga upp koden men internet strular på den andra datorn (ja jag sitter med två datorer samtidigt, hehe).
måndag 4 juni 2012
TextField, layout, text&graphics
Lecture 21.
TextField, Layout (Grid and Table) and Text & Graphics. Again a lecture with a lot of code. I am going to dive right into that any second now.
TextField, Layout (Grid and Table) and Text & Graphics. Again a lecture with a lot of code. I am going to dive right into that any second now.
Etiketter:
Stanford Uni
Interactors( GUI)
Lecture 20.
GUI - Graphical User Interface
Interactors
A lot of coding in this lecture. I had to change a lot in his code because i don't have access to the Stanfords own library (which what I understand has a lot of methods already written in it to simplify for the students). Anyhow, interactors are buttons, sliders, checkboxes, radio buttons, combo box and text box.
Don't forget to create an instance variable if you need to keep track of the variable between methodcalles.
Ex.
pick = new JComboBox();
......
}
private JComboBox pick;
GUI - Graphical User Interface
Interactors
A lot of coding in this lecture. I had to change a lot in his code because i don't have access to the Stanfords own library (which what I understand has a lot of methods already written in it to simplify for the students). Anyhow, interactors are buttons, sliders, checkboxes, radio buttons, combo box and text box.
Don't forget to create an instance variable if you need to keep track of the variable between methodcalles.
Ex.
pick = new JComboBox();
......
}
private JComboBox pick;
Etiketter:
Stanford Uni
fredag 1 juni 2012
Iterator
Lecture 19.
Iterator
-> lists through set of values
ArrayList
ArrayList<String> name new ArrayList<String>( );
Iterator<String> it = names.iterator( );
//Always ask if there are any values left
while(it.hasNext()){
println(it.next());
}
HashMap
Don't have the values in order.
//You ask for the key and not the corresponding value
Iterator<String> i = phonebook.keySet( ).iterator( );
//And then use the whileloop
If you don't want to create the iterator there is a new way of writing:
for (String name : phonebook.keySet()){
println(name)
}
Iterator
-> lists through set of values
ArrayList
ArrayList<String> name new ArrayList<String>( );
Iterator<String> it = names.iterator( );
//Always ask if there are any values left
while(it.hasNext()){
println(it.next());
}
HashMap
Don't have the values in order.
//You ask for the key and not the corresponding value
Iterator<String> i = phonebook.keySet( ).iterator( );
//And then use the whileloop
If you don't want to create the iterator there is a new way of writing:
for (String name : phonebook.keySet()){
println(name)
}
Etiketter:
Stanford Uni
Interface, Map and HashMap
Lecture 19.
Interface
-> set of methods
-> common functionality among a set of classes
Syntax: public class ClassName implements InterfaceName
Interface is more general than extends.
Map (interface)
Key
Value
An association between a key and a value. Always keysensitive.
Ex. Dictionary - a map
words - key
defintions - value
Ex. Phonebook - a map
names - key
numbers - value
HashMap (class)
-> implements Map
template -> 2 types ( one type for your keys and one for your values)
HashMap<String, Integer> phonebook = new HashMap<String, Integer>( );
Methods most commonly used: put and get, but also remove, containskey and size.
phonebook.put("Mehran", 7236059);
phonebook.put("Jenny", 8675309);
Integer MehranNumber = phonebook.get("Mehran");
phonebook.remove(key); //removes key AND value
phonebook.containskey(key); // returns a boolean
THINK of it as a bag where you put things in pairs. No order.
Interface
-> set of methods
-> common functionality among a set of classes
Syntax: public class ClassName implements InterfaceName
Interface is more general than extends.
Map (interface)
Key
Value
An association between a key and a value. Always keysensitive.
Ex. Dictionary - a map
words - key
defintions - value
Ex. Phonebook - a map
names - key
numbers - value
HashMap (class)
-> implements Map
template -> 2 types ( one type for your keys and one for your values)
HashMap<String, Integer> phonebook = new HashMap<String, Integer>( );
Methods most commonly used: put and get, but also remove, containskey and size.
phonebook.put("Mehran", 7236059);
phonebook.put("Jenny", 8675309);
Integer MehranNumber = phonebook.get("Mehran");
phonebook.remove(key); //removes key AND value
phonebook.containskey(key); // returns a boolean
THINK of it as a bag where you put things in pairs. No order.
Etiketter:
Stanford Uni
Debugging
Lecture 18.
Design - Architect
Coding - Engineer
Testing - Vandal!
Debugging - Detective
Always be a vandal!
Bad values, faulty logic and unwarranted assumptions (ex. feet instead of meters) causes bugs.
- Most of the problems are SIMPLE
- Be systematic
- Don't make assumptions about the problem(s)
- Be critical (< instead of >)
And don't panic!
Use println to find bugs. Ex. before and after a method or writing out variables.
Unit test - test one unit at the time (with values you give)
Design - Architect
Coding - Engineer
Testing - Vandal!
Debugging - Detective
Always be a vandal!
Bad values, faulty logic and unwarranted assumptions (ex. feet instead of meters) causes bugs.
- Most of the problems are SIMPLE
- Be systematic
- Don't make assumptions about the problem(s)
- Be critical (< instead of >)
And don't panic!
Use println to find bugs. Ex. before and after a method or writing out variables.
Unit test - test one unit at the time (with values you give)
Etiketter:
Stanford Uni
Arraylist vs array
Lecture 18.
Arraylist
+ dynamic resized
+ other operations
- less efficient than an array
- syntax is bulky (more errors can occur)
- pre version 5.0
If you have a fixed size (almost) always use an array!
Arraylist
+ dynamic resized
+ other operations
- less efficient than an array
- syntax is bulky (more errors can occur)
- pre version 5.0
If you have a fixed size (almost) always use an array!
Etiketter:
Stanford Uni
Kodat
På förmiddagen har jag ägnat mig åt att skriva klart koden till arraylistövningen som Mehran går igenom i lektion 17. Det gick lätt som en plätt. Sen försökte jag mig på att göra den sista övningen han gick igenom men fastnade tyvärr. Hade varit lite roligt att få till "regnande siffror" med hjälp av musklickande. Menmen tids nog...
Prenumerera på:
Inlägg (Atom)