API - An API is a collection of code usually presented in the form of a non executable jar file didn't you ever wonder why the words
System.out.println(); were so magical anyways? They aren't! This to is part of a API included by default in Java.
There will be a link to Java's default API at the bottom of this article in resources!
void() boolean() int() double() etc... - These are all return types a void is a method that runs the code inside the brackets when called.
public private - these are types of visibilities if something in the cat class is marked as private even if its private static you won't be able to call it
from another class the reason for this is because its marked as private and belongs only to the cat class private should be abused as much as possible
whenever you don't need a particular piece of code for another class.
variable - a variable is a boolean int or anything else which you record in your code for use later.
Call - A call is when you call for a method a good example is right below this.
Method - A named place in code that can be called upon at a later time.
Code:
public class Main {
public static void main(String[] args) { //the starting point of any program
/*
* Calls method printHello(); from class OtherClass
* args is a array of strings args[0] reffers to the first string in the array (we start at 0)
* my argument 0 from the command line is "Hello I am arguemnt 0."
* Java src.main "Hello I am argument 0."
* */
OtherClass.printHello(args[0]);
}
}
Code:
public class OtherClass {
/*For this example printHello() is a method and String s is a argument passed to the method.
* s is passed to the method from the point of its call look back to main.java
* note that args[0] a string was between the parentheses OtherClass.printHello(args[0]);
*/
public static void printHello(String s) {
System.out.println("Hello World!");
System.out.println("This class was an attempt to show the relation between java classes!");
System.out.println("This was the first argument passed to the program: " + s); //s is a string
}
}
Object - A object is a class that has a constructor the creation of a object is always instanced meaning it gets its own set of values. Two cats will never be the same!
Constructor - A constructor is a set of values a object needs for instance a cat(the object) needs to have a age and a color (among other things):
Code:
public class Main {
public static void main(String[] args) { //the starting point of any program
int age = 1;
String color = "PurpleBecauseWhyNot.";
/*
* Create a new cat use the age variable defined as 1 and the color variable defined as
* "PurpleBecauseWhyNot."
*/
Cat fluffy = new Cat(age, color);
/*
* Because this method was a return type of String we can use this here and it will
* print to the console "PurpleBecauseWhyNot." because thats the fur color of the cat object
* named fluffy that we gave it when we created it using
*
* String color = "PurpleBecauseWhyNot.";
* Cat fluffy = new Cat(age, color);
*/
System.out.println(fluffy.getColor());
}
}
Code:
public class Cat {
/*
* The below is a example of a constructor the object Cat is constructed with the values
* int age and String color because all cats have ages and colors!
*/
private int age; //this is seen below getting set to the value of the passed variable of passedAge
private String color; // ^ what that guy said.
public Cat(int passedAge, String color) {
this.age = passedAge;
this.color = color;
}
/*
* This is a example of using a return type if we used a void the code would have been executed
* and Java would have continued on top down but since we used string when it returns to where it was
* it will pull the value of color along with it!
*/
public String getColor() {
return color;
}
}