EXPLAIN THAT PLS IN DETAILS. THANK YOU

0 Kirill Lukenyuk · April 15, 2015
What the heck does void and static mean???
Bucky said that void returns no value, but than he writes that in your first gf.. method (method called saying in tuna class)
guys pls. help. This is so much confusing as well as all 16 tutorial unfortunately..
thanks everybody who is willing to help

Post a Reply

Replies

Oldest  Newest  Rating
0 steven kitchener · April 15, 2015
Hey Kirill,

I guess your talking about the void in a method call, something like public void someMethodName();

If so then this tells the method what return type it will be taking. Methods, If you didnt know, are able to return something from them if need be, most common are the "getter" methods i.e. getX() returns an x value of an object. 

However not all methods will return a value, and this is where the keyword void comes into play. If you define a method body with the void keyword then you are telling Java that this method will not be returning anything from it. 

Static things are a little more complicated to understand (and explain for that matter) and as you have stated above your finding the first few tutorials confusing so im not going to go into detail regarding the static keyword. I will however urge you to avoid using it until you have a better understanding of Java code.

Stick to using Getter and Setter methods (which should have been covered by Bucky by now) to move information around your classes.

Hope this helps,

Steven
0 Kirill Lukenyuk · April 15, 2015
Unfortunately Bucky did not explain it probably as clear as it suppose to be or those tutorials
ain't for beginners, maybe that's why I'm kind of confused idk
Now I understand it better and I finally found information about static thing.
thanks a lot Steven!
0 Kuroodo Ditory · April 16, 2015
Here is an example:


public class CoolClass{

private boolean myBoolean = false;

public void setMyBoolean(boolean b){
myBoolean = b;
}

// We will return a boolean value
public boolean getMyBoolean(){
return myBoolean;
}

}


//Then here is a different class.

public class mainClass{

public static void main(String[] args){
  CoolClass myObject = new CoolClass;

  myObject.setMyBoolean(true);

  System.out.println(myObject.getMyBoolean());
}

}



The output is:
true

So we used the setMyBoolean method to set myBoolean to true. Then we used getMyBoolean to return myBoolean. setMyBoolean is called a setter, and getMyBoolean is called a getter. You can use getters to return values or to return objects and do whatever you want with them (change their values, check their values, etc, etc). 

Note: You need to know about classes and objects to understand the example I used above. So if you don't understand that yet and find my example hard to follow, it's pretty much like Steven said, they just return a value and void doesn't.



For static, go here https://www.thenewboston.com/forum/topic.php?id=4026
0 Nicholas Eason · April 16, 2015
void means that the method returns nothing when called.

static means that you can use this object/method without creating an object of the class. One example that you may understand by now is System.out.println();

The reason you call System.out.println() and dont get an error is because println is a static method. You don't need to make an object of out to use it.
  • 1

Java / Android Development

107,026 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator