# Java Programming Tutorial Part2 - Netbeans, Classes and Sample Project



## Oliver_FF (Aug 16, 2008)

*Netbeans*
Netbeans is a FREE java IDE that has loads of cool features (any many totally unnecessary, as with most IDE's these days).

Netbeans is available for download here: 
http://download.netbeans.org/netbeans/6.1/final/
You want any bundle as long as it contains Java SE - thats Java StandardEdition  The IDE also does loads of other stuff - if you're interested you can get the giant bundle, or just the Java SE bundle. Whatever floats your boat. 


*Sample Project*
Ok, so i've been doing some thinking about some simple easy project thats not as boring as hell... I've come up with creating a small app that acts as like a forum. You can create users, post in threads in forums etc etc. There's plenty of scope for people to add to the project and learn new things should they want to.

*Desired functionality in v1:*

Be able to create a number of users
Be able to create a number of threads
Be able to post in threads
Be able to view threads
I will assume for the moment that there is only one subforum to post in.


*Creating our project*





Once you've installed netbeans, open it up and go to File -> New Project.





Pick a new Java Application





I'm going to call this "TPUForumExample" and click Finish.

There's the basis for out project 

*The First Step*
Ok, first up we're going to create a Class called "user" which will represent each person who uses our 'forum'.





Right click on the top of the tree on the left and select New -> Java Class...





In the new window, name our class "User" (with a capital U) and pick our projectname from the Package option. Click Finish.






*Data types in Java*
Whenever you want to store some data in Java you have to chose what data type you want to use for it. Here are some of the main data types and examples of data you put in them.

```
Name     | Descrption            | Examples
-------------------------------------------------------------------------
String    Series of characters    "Oliver_FF", "The Ninj4", "Bob", "12345"
int       Whole numbers           1, 56, 9990, 374362, 3434333
double    Decimal numbers         56.993, 573.222, 0.001, 6666992.2
boolean   True/False              True, False
char      Single character        'a', 'b', 'h', 'w', 'z', '1', '@'
```


*The structure of a Class*

```
public class [Class Name]
{
    [Fields]

    [Constructor]

    [Methods]
   
}
```
*Fields:*
Fields are where you store data that is relevant to the class you are working in. In our User class for example, things like the user's name, their signature, post count etc are all data items that might be Fields.

*Declaring a Field:*

```
private [type] [name];
```
It is good practise to declare ALL fields as PRIVATE. I'll explain what another time.

*Adding Fields to our User class:*
Ok, so here's a list of a few things that I think we should store about each User:
1. Their username
2. Their password
3. Their email address
4. Their signature
5. Their post count

Now, we need to decide what data types to use. Numbers 1-4 are variable length series of characters, so we will use Strings. Number 5 will be whole number values, so we will use int.


```
private String userName;
private String password;
private String email;
private String signature;
private int postCount;
```


*Methods:*
Methods define how the objects in your program interact with eachother and themselves. You use them to pass data between objects or to process data - things like that. For out User class, we'll only be needing some very basic methods to access the data inside the User objects.

*Declaring a Method:*

```
[public/private] [return-type] [name]([parameters?])
{
    return [data];
}
```


*Adding some methods to our class:*

```
public String getUserName()
{
   return userName;
}
```
This method will simply get the username contained inside a User object.


```
public void setUserName(String newUserName)
{
   userName = newUserName;
}
```
This method takes a String parameter, and uses it to set the username of a User object.

How methods are used and how they fit together will become apparent in the next part, when we create the Post class.


*The Constructor:*
The constructor is basically a method that is run when you first create an Object out of a class. For now we will not bother with one (Java will default to an empty constructor if none are provided).


*Next Time:*
Creation of the Post class. 
More data types. 
Stuff...

Lots more will become apparent as soon as the second class is completed. Hopefully lightbulbs should start clicking soon


----------



## Kreij (Aug 26, 2008)

Nice job, I'm looking forward to your next installments !


----------



## Oliver_FF (Aug 27, 2008)

It's actually well hard to get out the really basic concepts 

I'll try and clear everything up in part3... i got distracted by the bank holiday weekend and ended up doing nearly 300miles on my motorbike


----------



## Kreij (Aug 27, 2008)

I agree. Once someone undestands the concepts of OOP then learning the various languages is just a matter of learning the syntax and API calls. The modern OOP languages all accomplish the same thing with only variations in implimentation.

I remember the good old days when the language you used was dictated by the function you wanted the program to perform (ie. if you were doing high level math, like FFTs, you used Fortran. Period.)

It's still true to some extent today, but the lines have greatly blurred due to the inclusion of thousands of API modules and functions and the great job of optimization that the latest compilers do.

Anyway, go ride your motorcycle all you want. No hurry on the tutorial


----------



## bruwmac (Jun 20, 2010)

Did you ever continue this tutorial?


----------

