Before I start his tutorial I'd like to say it is 100% MINE i am just transferring it over from my old HF account.
Hello Everybody! My name is Daniel and I will be your Basic Command-Line Java teacher for today!
What I Expect:
1. I expect you to know nothing
2. I expect you to have an IDE
3. I expect you to WANT to learn
What You Can Expect:
1. A whole new look at JAVA
2. You should be able to make an basic-intermediate program with java
quick info: this tutorial is written WITHIN the code, where I explain each line interactively.
Lets Get Started!
Lesson 1: Hello World!
Lesson 2: Variables//Hello World Program /*the {} next to the class and the method is called a code block, * all the code for that class and/or method should be surrounded by {} */ public class tutorial {//a class is the name of the file you are working in public static void main(String[] args){//This is the 'main' method, it is used in EVERY java program System.out.print("Hello World!");// this is your basic output function //System.out.print("Hello World!); tells Eclipse that you want it to output to the screen "Hello World!" //all lines of code in java (other then ones that use code blocks) end with ; System.out.println("Goodbye World!"); /*the above code displays "Goodbye World!". however, as you can see it has "ln" after print * this tells Eclipse that you want to output this text on a new line */ System.out.println("Hello \n Goodbye"); /*the above code displays "Hello" on one line and "Goodbye" on another (\n means new line) * \n is very useful because you can write long sentances but output them neatly */ } }
Lesson 3: Arrays!//variables! public class tutorial { public static void main(String[] args){ int INTVARIABLE = 1;//int is an integer variable (only whole numbers can be ints) double DOUBLEVARIABLE = 1.5;//this is a double (doubles can be decimals or whole numbers) String STRINGVARIBALE = "This is a string variable, it holds text"; System.out.println(INTVARIABLE);//this will print out INTVARIABLE System.out.println(DOUBLEVARIABLE);//this will print out DOUBLEVARIABLE System.out.println(STRINGVARIBALE);//this will print out STRINGVARIABLE //adding ints and doubles int A = 2; int B = 2; int C = A + B;//adds A (2) and B (2) together System.out.println(C);//will print out A + B (4) double Q = 1.5; double W = 2.5; double E = Q + W;//adds Q (1.5) and W (2.5) System.out.println(E);//will print out Q + W (4) //Adding Strings Together To Make One Sentance String first = "Hello"; String second = " Hack"; String third = " Forum!"; System.out.println(first + second + third);//prints out "Hello Hack Forum!" } }
Lesson 4: Input!//Arrays! public class tutorial { public static void main(String[] args){ //arrays are a group of variables put together int INTARRAY[] = {1,2,3,4,5,6,7}; /*this array is an integer array with ints seperated with commas * to declare an array you need to declare its type then its name with [] next to it */ String STRINGARRAY[] = {"Hello","Hack","Forum","!"}; /*this is a String array, it is the same as the int array just with strings * This array is used to hold many strings at a time */ System.out.println(STRINGARRAY);//Prints String Array System.out.println(INTARRAY);//Prints Int Array //arrays count their objects starting at 0, so in the intarray '1' is actually in the 0 spot //to call a specific object we do the following System.out.println(INTARRAY[0]);//prints '1' System.out.println(STRINGARRAY[2]);//prints 'Forum' } }
Lesson 5: If Statments!//Input! //to begin, we need to import the Scanner module import java.util.Scanner; public class tutorial { public static void main(String[] args){ //now we need to make a Scanner object which will read what is inputed Scanner name = new Scanner(System.in);//creates a scanner object named "name" System.out.print("Enter Your Name: ");//prints this out String input = name.next();//reads what ever input follows System.out.println("Welcome " + input);//prints out "Welcome " and whatever you input } }
//If Statement import java.util.Scanner; public class tutorial { public static void main(String[] args){ String InputName = "John"; Scanner name = new Scanner(System.in); System.out.print("Enter Your Name: "); String input = name.next(); if (input == InputName){//if the input is exactly equal to "InputName" then... System.out.println("Hello " + InputName); } else if (input != InputName){//else, if input does not equal InputName then... System.out.println("Hello " + input); } else{//else, if none of the above is true then this will happen... System.out.println("Hello"); } int i = 1; int a = 2; if (i < a){//if i is less then a... System.out.println("i<a"); } else if (i > a){//else, if i is greater than a... System.out.println("i>a"); } else if (a >= i){//else, if i is greater than or equal to i... System.out.println("a >= i"); } else if (a <= i){//else, if a is less than or equal to i... System.out.println("a <= i"); } } }
More to come! if you have any questions you can either add me on skype (bigxexsmalls), comment here or pm me! Thanks!