Monday, April 30, 2012

Oracle vs Google, Who loses?

   Either way the lawsuit turns out  I am pretty sure developers and users will be worse off. Perhaps I should have tried to learn how to make Apple apps, just joking. I have been reading how developers first make Apple apps then transfer it over to Android but that is a whole other language  and I have my hands full with Java and Android. So I will ride this lawsuit out and make the best of it.

10,000 hour to mastery.    
10,000 - 85.75 = 9914.25 hours left     

Thursday, April 26, 2012

Progress in Mastery?

   If you have been reading my blog you know that I have been keeping track of how many hours  I spend studying  Java and some Android with the ultimate goal of being able to program decent Apps.  Which consists of reading books, Ebooks, websites, video tutorials and hands on programming  using Eclipse. How much better am I at understanding  all of it  I can not say quantitatively. I can say I "feel" like I know it better and I have been able to figure out how to program the exercises ( see previous posts).

   I think the main advantages of the "10,000 hours to Mastery" schedule/program is.
It gives me a goal.
Keeps me motivated.
It keeps me from lying to myself about how much I am studying.
And it gives me a better idea of how I have been studying.

   How many years will it take to  reach 10,000 hours?
80 hours divided by 71 days ~ 1.12676 hours per day
10,000 divided by 1.12676 ~8875 days
8875 divided by  365 ( not counting leap years)
24.315 years

   So about 25 years, a little discouraging but you have to keep in mind  that you don't have to be a Master of a language to write fairly  decent programs

10,000 hour to mastery.    
10,000 - 80 = 9920 hours left    
 


Wednesday, April 25, 2012

The importance of placement

  I spent a while typing in a long example  from a book  and Eclipse was giving me two error indications that were related.
Error  message
----------------------------------------------------------------------------------------------------------
No enclosing instance of type KnightMoves is accessible. Must qualify the allocation with an enclosing instance of type KnightMoves (e.g. x.new A() where x is an instance of KnightMoves).
---------------------------------------------------------------------------------------------------------

 I spent a half hour looking over what I typed  and what was in the book. I just could not find the problem. Finally after almost giving up on it I saw that I had placed a bracket '{' in the wrong spot. So Eclipse saw that all  brackets were accounted for  but did not know that one was in the wrong spot. It turns out I placed the bracket that closes main( ) at the end of another class that was added at the bottom. Lesson learned I hope.

Monday, April 23, 2012

StumbleUpon

   There is a cool site that will show you random web pages based on your interests. I found some cool Java sites using it.  www.stumbleupon.com is the site. You check mark all the things that interest you from a long list they provide then you click the stumble button. You can give a thumbs up or down. You can see what other stumblers are liking. I have to warn you though, it is addictive . You will spend hours clicking and clicking. Bookmarking way to many pages.

10,000 hour to mastery.    
10,000 - 75 = 9925 hours left    

Friday, April 20, 2012

Feel good moment

I had an exercise in which I had to read from a text file -a student's name and three grades they received  then print out the name, grades and the average of these three grades. The  main problems I had with this exercise  was  1, finding the file ( I had to use a lot of  back slashes "\" in the file path) . 2, reading each line in the  file. 3, converting a string number  to a double and 4,  formatting the double to only two decimal places. Of course I had to put a lot of this  in a try / catch block. Here is the code, leave a comment if you have any suggestions.

// Exercise 2.6


package my.java.classes;


import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;


public class StudentAverage {


public static void main(String[] args) {


double average = 0;
double grade = 0;
double total = 0;
// location of text file to be read
File file = new File(
"C:\\\\workspace\\My Java programs\\bin\\my\\java\\classes\\testdata.txt");


BufferedReader reader = null;


try {
reader = new BufferedReader(new FileReader(file));
String name = reader.readLine();// reads first line
System.out.println(name);
String text = null;
// read the next three lines of text file
while ((text = reader.readLine()) != null) {
grade = Double.parseDouble(text);// convert to double
total += grade;// add line read to lines already read
System.out.println(grade);


}
//catch possible errors
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
average = total / 3.0;
DecimalFormat df = new DecimalFormat("#.##");
// create an object to format average answer
String averageFormatted = df.format(average);
System.out.print("Average grade is: ");
System.out.print(averageFormatted);


}//end of main()
}//end of StudentAverage class


10,000 hour to mastery.    
10,000 - 72.25 = 9927.75 hours left   

Friday, April 13, 2012

Second Class

  I was trying to run an example from one of my books. I kept getting an error about the class "Employee" already being defined. I double checked my typing  and could not find anything wrong. I tried commenting out sections but still could not find the problem. Then it occurred to me that the trouble might be outside of the example program I was trying to run.  The problem was that  I had another class "Employee" in another example and both were in the same project folder. I have been putting all the programs from examples in the books in the same project folder instead of making separate projects So I deleted that older program  and the new one ran fine.

10,000 hour to mastery.    
10,000 - 64.5 = 9935.5  hours left   

Thursday, April 12, 2012

Javanotes5

   There is an app I have downloaded Javanotes5. A nice introduction to programming using Java. It comes with quizzes ,exercises and answers to them. It uses an older version of Java with different methods in the beginning  then what I have been reading in other books. An example is these output methods.

TextIO.put("The message" ); //old version, the one the lessons use

System.out.print("The message" ); // new version , not used in the lessons until later

 The author Professor David J. Eck says he does this because " it requires some knowledge of object-oriented programming to use the class, so it's not appropriate for use here at the beginning of this course."

All in all I would still recommend the app

10,000 hour to mastery.    
10,000 - 62.5 = 9937.5  hours left  

Monday, April 2, 2012

Auto import troubles with Eclipse

   I was trying to setup a timer for a class TickTock ( from a book). I needed-(  import javax.swing.*; ) but Eclipse has an auto import feature that imports libraries you need  and for some reason  it kept giving me,

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.management.timer.Timer; <----(this is not the one I needed)
import javax.swing.JOptionPane;

What I needed was this.
import javax.swing.Timer;


Also Eclipse won't let me use - import javax.swing.*;  it corrects it and only imports the methods you actually use.
Perhaps import javax.management.timer.Timer;  is the new preferred version.

Strangely I was able to get it to work by  pasting the code from the website. When I did that  , Eclipse auto-corrected but inserted import javax.swing.Timer; ( website code had - import javax.swing.*; )
This can be confusing if you are trying to go by examples in the book. 

10,000 hour to mastery.    
10,000 - 50 = 9950  hours left