Saturday, March 3, 2012

Java Lesson #2: The print and println methods.


If you have not read the previous lessons you can do so by going here.

For this Java lesson I am going to teach you the print and println methods. You may remember that we used println to print out the words "Hello, World!".

The System.out object represents an output device or file, which by default is the monitor screen. We use the println method whenever we want to print something out. Another method we can use with System.out is print.

So we have to ways to print something out but what the difference? Find out by typing up the following program and running it. Remember to save it as Pizza.java
If you need help please see the previous lesson.



So have you figured out what the difference is? During execution if you invoke the println method it advances to the next line after it prints. If you use the print method the next thing that gets printed will be on the same line.


So there you have it. That's today's lesson. Comeback tomorrow to learn about String concatenation.

Thanks for reading this lesson and if you found it helpful please help me out and pass this information along. If you haven't signed up to get these lessons emailed to you, sign up over there --->

Wednesday, February 29, 2012

Your First Java Program: Hello, World!



For your first Java program we are going to code the world famous "Hello, World!" program. If you're going to code in other languages I guarantee you'll see this same program many times.

To start, open up your text editor and type the code in exactly how you see it to the right.

Save it as HelloWorld.java

The filename must always be what is after public class.

Now you need to compile and run your program. Open your command prompt and point it to where you saved your program. I save mine on my desktop so I typed: cd Desktop (Note: I am using Linux so mine will probably look different than yours.)



 Now you can compile your program by typing: javac HelloWorld.java



After it is compiled your computer should have made a new file in the same folder as your program but instead of a .java file it will be a .class file. That is your compiled program.

You can now run your program by typing: java HelloWorld


Congratulations on making your first Java program!

For more tutorials please subscribe by entering your email over there -->
or bookmark us and comeback daily for a new lesson.

If you have any problems comment below and I will do my best to help you out.