• Post Reply Bookmark Topic Watch Topic
  • New Topic

Struggling Java Newbie.  RSS feed

 
John Stuart
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, I've just started learning Java and have some difficulties understanding basic Java programming terms. These terms are:

1. Class
2. Object
3. Methods
4. Instance
5. Instance Variable
6. Others (e.g., member variable, class variable, member methods, instance methods, and many more)

I've been doing some research on my own and these are the results. Please correct me if I'm wrong.

1. Class
- In Object Oriented Programming, class is a place to create objects, methods, and initializing variables. Example of class in Java:
public class javaapplication1() {
<code here>
}

2. Object
- In Java, object is a location in computer memory with a value and identifier (name) assigned to it. variable and methods can be considered as object. Example of object in Java:
I don't know. I understand the concept but I can't demonstrate it. But I do know how to make class as an object to access its methods.

3. Methods
- Methods is a procedure. You can call methods as many times as you want. Method is like function in other programming language. Method is what a class can do (or object? can you consider class as an object?) .
Example of methods in Java:
public void displayStuff() {

}
You can easily identify methods by looking at the set of parentheses after the method name.

4. - 6.
I really have no idea about these terms. Do I need to understand these to be able to proceed deeper into Java programming?

If you want to provide explanation, please explain it like I'm a grade schooler trying to learn programming.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Stuart wrote: . . . class is a place to create objects, methods, and initializing variables. . . .
No. It would be better to say that a class is a design for creating objects. It tells you which fields and which methods an object will have, and in the case of methods, what those methods will do.

And welcome to the Ranch
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Stuart wrote: . . . - In Java, object is a location in computer memory with a value and identifier (name) assigned to it. variable and methods can be considered as object. . . .
No. An object is some software/memory representation of something. Objects usually encapsulate behaviour (=methods) and data (=fields).

Behaviour and data (to repeat). You usually have both in an object. Obviously the object often uses the behaviour to manipulate its data.

A field or a local variable in Java® is a means of hiding the memory location where you will find an object. (That doesn't apply if the field/local variable is a “primitive”. Primitives contain their exact value, e.g. 123 [beware of my confusing statements in that link]). If you have a variable called text, the JVM will use that name text to find the memory location where that text can be found. There is no straightforward way for you to find that location in Java®.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Stuart wrote: . . . 3. Methods
- Methods is a procedure. You can call methods as many times as you want. Method is like function in other programming language. . . .
An object can do things with data and it uses its methods to do those things.
Don't say function and procedure, because
  • 1: Those names are not usually used in Java®: we say methods.
  • 2: Function and procedure have specific meanings and you should use those terms for their specific meanings.
  • There are a few methods which do not need any other data, e.g. log (for logarithm), and these are sometimes run from the class, but that is a minor point.

    You can have fields and you can have methods with the same name and the compiler distinguishes the two by looking for (), so you are right about that bit.
     
    Travis Roberts
    Ranch Hand
    Posts: 54
    C++ Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    John Stuart wrote:So, I've just started learning Java and have some difficulties understanding basic Java programming terms. These terms are:

    1. Class
    2. Object
    3. Methods
    4. Instance
    5. Instance Variable
    6. Others (e.g., member variable, class variable, member methods, instance methods, and many more)


    An instance, in object-oriented programming (OOP), is a specific realization of any object. An instance variable is going to be a piece of data that belongs to that object. A class variable is going to be a piece of data that is shared among every class object that gets created. If you created a class named Student and created a new instance of student for every person enrolled, you are going to have a lot of instances of student. Each of those students are enrolled at the same school, so it doesn't make sense to make an instance variable of schoolName. If you have 9,000 students you are going to have 9,000 schoolName variables taking up space in memory. So you can create a class variable name which basically just creates the variable once and forces it into every instance that gets created from a specific class.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!