I'm starting to teach a friend about the basics of java and I wrote up this example class to demonstrate them. I figured someone on here can use it to learn so I'm going to post it here for you to do whatever with it. Maybe some leechers can learn something for once eh?
Here it is:
Code:
/*
* Classname = Tester
*
* Version information = null
*
* Date = 3/30/12
*
* Copyright notice = null
*/
/**
* This is a small tutorial to explain java basics
* Written by Austin Melchior AKA Sillhouette for Joey
* Released to the public
* Resources used: Java conventions defined by Oracle
* http://www.oracle.com/technetwork/java/codeconv-138413.html
*/
/**
* We will start off by looking at the placement of code
*/
/*Package statement goes here*/
///No package currently
/*Imports go here*/
import java.util.*; //This imports the java.util package
//the "*" refers to all files in that directory
/*
* Now you declare your class
* @public, public is the scope of the class
* that will be talked with in further depth later
*/
public class JavaTutorial {
/**
* Comments on what the class is for go here
* This class is merley to test different basic concepts
*/
/*Next we add the variables of the class
* The order of these is as follows:
* First the public static class variables, then the protected static,
* then package static level (no access modifier), and then the private static
* then the public class variables, then the protected,
* then package level (no access modifier), and then the private.
*/
///Static Variables
public static int statInt = 7; //Integer between roughly -2.147b and 2.147b
protected static double protStatDbl = -54.5; //Double is a number that has a decimal point
static boolean pkgStatBoolean = false; // Booleans have only two values, True and False
private static String prvtStatString = ""; // A string is a decleration of a string of characters, like a word
///Non-Static Variables
public double pubDbl = -5735.68; // Declaring a variable and assigning a value can be done in the same line, assigning a value is called instantion.
protected boolean protBoolean; //You can declare variables without assigning a value, this is called decleration.
char pkgChar = 'c'; // A char is a single character, can be anything from "~" to letters or even numbers
private long prvtLong= 6857 * 5683; //You can declare numbers by suing arithmatic equations as well, A long is a number bigger the 2.147b,
/*
* Now we have the constructors, Both default and non-default
* You can have as many constructors as you want as long as they have different parameters
* Constructors are always defined by the class name, a few examples are given
*/
///Default Constructor
public void Tester(){
protStatDbl = pubDbl * statInt;
}
///Non-Default Constructors
public void Tester(int input1, String input2, boolean input3){
input3 = protBoolean;
input2 = prvtStatString;
input1 = statInt;
}
/*
* Now we have the methods
* Rather then being grouped by scope, methods are grouped by functionality and readability
* Methods are defined with a return type eg: int, String, or void(returns nothing)
* A few examples are given below.
*/
public static void main(String args[]){
//This is the main method used to run a java applet or application
}
//returns an int
public int intMethod(){
int temp = 2 * statInt;
return temp;
}
//returns nothing
public void voidExample(){
for(int i = 0; i < 2; i++){
i = i + 2;
}
}
}
And here it is as a notepad file:
http://up.ht/HaMO2J
I'm open to any and all suggestions or criticisms rate/hate
Thanks all