Here is a link to some notes that may be helpful:
(You may have to cut and paste the link into your browser)
http://www.greenleecds.com/javaAPhome.html
Wednesday, January 14, 2015
Monday, December 22, 2014
Saturday, December 6, 2014
How to Initialize ArrayLists (not like Array initialization)
Here are two ways to initialize an array:
int [] x = { 1, 2, 3, 5 };
Of course, you can also initialize Arrays manually, like this:
int [] x = new int[4];
x[0]=1;
x[1]=2;
x[2]=3;
x[4]=5;
Now lets look at the comparable ways to initialize an ArrayList of Integers:
Here is the manual way:
ArrayList<Integer> x = new ArrayList<Integer>();
x.add(1);
x.add(2);
x.add(3);
x.add(5);
If you try to use the {} to initialize an ArrayList, it will not work:
Arraylist<Integer> x = {1, 2, 3, 5}; // this will not compile
The above will not work because this syntax is not supported by java.
Here is the proper way to initialize an ArrayList in a single line of code:
ArrayList<Integer> x = new ArrayList<>(Arrays.asList(1, 2, 3, 5));
What is happening in the above line of code is that the Arrays class is providing a static method called asList(), which is taking the numbers and converting them to an ArrayList. The variable x is then used to point to the newly created list.
This latter (more sophisticated) method of initializing an ArrayList is NOT tested on the AP exam (or my exams) but is handy. I am showing it to you here because I have used it in your ArrayList Intro Lab and did not want you to get confused by it.
mr. sarkar
int [] x = { 1, 2, 3, 5 };
Of course, you can also initialize Arrays manually, like this:
int [] x = new int[4];
x[0]=1;
x[1]=2;
x[2]=3;
x[4]=5;
Now lets look at the comparable ways to initialize an ArrayList of Integers:
Here is the manual way:
ArrayList<Integer>
x.add(1);
x.add(2);
x.add(3);
x.add(5);
If you try to use the {} to initialize an ArrayList, it will not work:
Arraylist<Integer>
The above will not work because this syntax is not supported by java.
Here is the proper way to initialize an ArrayList in a single line of code:
ArrayList<Integer>
What is happening in the above line of code is that the Arrays class is providing a static method called asList(), which is taking the numbers and converting them to an ArrayList. The variable x is then used to point to the newly created list.
This latter (more sophisticated) method of initializing an ArrayList is NOT tested on the AP exam (or my exams) but is handy. I am showing it to you here because I have used it in your ArrayList Intro Lab and did not want you to get confused by it.
mr. sarkar
Monday, November 17, 2014
Test Friday on Strings
The test will consist of 20 or so multiple choice questions (3 points each) followed by one or two long answer String problems. The long answer problems will be on the same level of difficulty as String-1 and String-2 in coding bat.
mr. sarkar
Thursday, November 6, 2014
Coin Game Now Due Wednesday
The coin game project due date has been moved to wednesday (11/12) because the class does not meet on monday due to the rotation. tuesday is a holiday.
Friday, October 24, 2014
Array exam will be Thursday, October 30th
The exam on Arrays will be on Thursday October 30th. It will feature multiple choice questions similar to those seen on the AP Computer Science exam but somewhat easier in difficulty. Since this exam is taking place during first block, please do not be late for class on this important date.
mr. sarkar
Monday, October 6, 2014
Extra Help After SChool Today (Monday 10/6/14) from 2:30-3:30 in the Lab (414)
Normally, extra help after school is from 2:10 to 3:10 but due to a parent-teacher meeting, extra help today will take place from 2:30 to 3:30. You are also welcome to use the lab from 2:05 to 2:30.
Subscribe to:
Posts (Atom)