Tutorials Navigation

Tutorials :: New :: Popular :: Top Rated

Tutorials: 18,357 Categories: 12

Total Tutorial Views: 42,406,678

Java Programming Tutorial 2 - The Basics Pt. 2

Tutorial Name: Java Programming Tutorial 2 - The Basics Pt. 2  

Category: PC Tutorials

Submitted By: Jimbo

Date Added:

Comments: 1

Views: 1,593

Related Forum: PC Building Forum

Share:




Jimbo's Java Class - Tutorial 2: The Basics Pt. 2

Previous Tutorial: Tutorials/id=23699/java-programmi...asics.html

Hello and welcome to my next Java tutorial. I'm professor Jimbo, an IT student at the University of Central Florida experienced in programming especially Java. In this tutorial I will further discuss the basics of Java programming.

Summary

In the previous tutorial I discussed the basics of setting up a project and getting your first project up and running. In this tutorial I'll be going more in depth of the basics of Java programming. In the next tutorial we will begin variables.

Getting Started

Last tutorial I left you all with an amazing cliffhanger.

public static void main(String[] args)

System.out.println("Hello TTG");

What exactly do these two lines of code mean? What do they do? Let's start with the first one. To make it easier I will break each word up.


public static void main(String[] args)

Public: The word public in Java is an access specifier that allows the main method to be accessed everywhere. This starts to become useful when you have projects with multiple classes.

Static: Static helps with other instances or objects to be called. Will rarely be used until in later tutorials.

Void: Void will clarify that the main method will not return any value.

Main: This is actually just the name of the method. Technically this can be named almost anything but for the sake of convention I always name it main.

String[] args: Here we are defining a String array. You will learn more about arrays in the later tutorials. As for args it's just the name of the array. It can be named almost anything but like main we name it args for convention.

If you ever want a shortcut to make this method there is an option to do so when creating the class:

[ Register or Signin to view external links. ]

I definitely suggest writing it out though that way you can memorize it.


System.out.println("Hello TTG");

This line of code is much more simpler than the first one. You start off by accessing the System class. Here is the definition straight from Eclipse.

"Among the facilities provided by the System class are standard input, standard output, and error output streams; access to externally defined properties and environment variables; a means of loading files and libraries; and a utility method for quickly copying a portion of an array."

It is then separated by a "." (which is use to separate both) followed by "out" which stands for output because you're outputting to the console. Println stands for "Print Line". Put them all together and you're telling the system class to output a printable string. As for the (""), you're writing inside the quotations what exactly you want to print. The line of code then ends with a semi-colon (;) which is basically the period of programming. It's ending the statement just like a period ends a statement.


Comments

Comments are extremely useful in any programming language and you should definitely get used to using them. They are completely ignored by the compiler so you can write whatever you want. To write a comment you can either do the following:

//
or
/* */

Here's an example:
[ Register or Signin to view external links. ]


Important Terms

Object: "Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behavior such as wagging their tail, barking, eating. An object is an instance of a class."

Class: A class is the template of the program. Kind of like a blueprint but it describes the behavior that the object of its type supports.

Method: A method is a behavior within the java program. It is designed to contain written logic, data manipulation and execute actions.

All three of these will be given examples in later tutorials.


Keywords

Key words also known as reserved words are words that cannot be used as an identifier (like a variable). Here is a list of keywords to remember:

[ Register or Signin to view external links. ]

source: [ Register or Signin to view external links. ]

Camel Case

Camel Casing is the last subject I'd like to discuss in this tutorial. It's a conventional term but almost all programmers use it. You can read more about it [ Register or Signin to view external links. ]

Conclusion

Congratulations! You now know enough basic information about Java programming to begin your journey on becoming a Java master. Make sure to check out the next tutorial as I will start discussing variables and fun little programs you can create using them as well as optional assignments that you can do to earn a gift of gold.

Questions?

Feel free to PM me here OR message me on the TTG discord.




Ratings

Current rating: 6.50 by 2 users
Please take one second and rate this tutorial...

Not a Chance
1
2
3
4
5
6
7
8
9
10
Absolutely

Comments

"Java Programming Tutorial 2 - The Basics Pt. 2" :: Login/Create an Account :: 1 comment

If you would like to post a comment please signin to your account or register for an account.

ValorPosted:

thanks for this im a total noob when it comes to programming