I Want to learn java for personal and maybe eventually professional use but every time I pick up book i lose focus forget everyhing and have to read it all over. Is there a better way to learn java or any programming language in general then by using a book like head first java?
views:
214answers:
8Think of an interesting project, and then try to implement it in the language you want to learn. That way you aren't just reading a book but are using it to do something useful.
EDIT: Personally, I would recommend picking a project that has some graphics to it. For me, seeing the program draw something cool on the screen helps keep me interested.
Sit down in a front of your computer, close browser!!!, turn off music, and then during reading a book try to enter and compile all examples and do all exercises.
I agree with the other answers - sitting in front of the pc programming (or trying to) is much more fun than just reading about it. Typing in the examples is a good start or loading them from the media supplied with the book, but also experiment with your own changes to the examples code.
Read trough the code, and ask yourself questions - why is there a semi colon there. What does that sign mean? Why is the method declared static? etc.. If you don't know the answer, use the book (or SO!) to find an answer.
Programming is a mathematical thing.. you need to practice a lot to get focused and learn (for real, as remembering on time) the language...
I will suggest, if you see anything that get you curious about how it have been done, try recreate it in the language you want to learn!... helps a lot.
You should first browse the book for some theories and ideas. While doing so or after reading, think of a little project where you can apply any of the concepts you have learned from the book. Even the simplest program like 'hello world' is a good start. Then slowly get to the more complex stuff. It would be simpler if you like what you're doing so focus on what will be helpful on your little project.
Motivation is an important factor.
You need first to define a goal, a simple objective that you want to achieve.
Then, instead of reading a book from A to Z, you try by yourself to implement that goal. Each time you block on something you don't know, check the book or on the Internet.
This way you'll be successful in small objectives, that will keep your motivation up.
Examples of goals:
- print sum of numbers from 1 to 10
- input a number N and display N dots on the screen
- input a word and change all 'a' with 'e'
- ...
Another matter that may not be relevant If the language itself is an issue, there are simpler and more fun languages to learn than Java, and easier to start with. For instance PHP.
You can try to write simple and fun (maybe a card game) programs at start. Than you can rewrite these programs with what you learned (advance OOP topics like extending objects, interfaces).
When your program becoming bigger and more complex you can realize you can not go forward without proper OOP design. With time you understand the OOP and I am sure that you find OOP exciting because it is the reflection of real world.
You can use Java Swing GUI input component for inputs, so you do not have to struggle with console input. Here is a example for Swing GUI inputs and outputs.
import javax.swing.JOptionPane; //just write this line at the top of your class
public class Main { // Main is your class name
public static void main(String[] args) { // that function is executed when program is opened
//simple text input
String str = JOptionPane.showInputDialog("Input some text");
JOptionPane.showMessageDialog(null, "your text is: " + str); //output
// turns your text input into a number
int x = Integer.parseInt(JOptionPane.showInputDialog("Input some integer number"));
JOptionPane.showMessageDialog(null, "your integer is: " + x); //output
}
}