how can i implement a function ex: 'add item' without using oop ?!

how exactly do you mean?
without using oop, you can have something like this:

public class Test{

public static void main(String args[]){
 addItem(1);
}

public static void addItem(int item){

}
}

but I doubt this is what you're looking for. normally, I expect an Item to be an Object, so that would be using OOP :)
also, I assume adding an Item would be adding it to an array, or a collection of some sort, which are ... objects :)

It doesn't help that there is no single universal definition of OOP, but I would say that if you just have static methods and don't declare any classes (other than the one the main method is in) and never use the "new" keyword, then your code has nothing "Object Oriented" about it.
Just to be safe, you should restrict yourself to primitive types (int, char etc) because these, by definition, are not Objects. I wouldn't worry about arrays - every non-OO language from C upwards has arrays, so I don't think they are necessarily "objects".

Edited 4 Years Ago by JamesCherrill: n/a

all i need is to implement an add item function without using oop

Absolutely right. The JLS chapter 10 begins "In the Java programming language, arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array."
My point was that even if Java treats arrays as objects, the fact that every non-OO language has arrays means that arrays in general are not necessarily objects, and using arrays isn't necessarily Object-Oriented. Plus, at a practical level, if you can't use arrays then what will the "add" method add to?

Absolutely right. The JLS chapter 10 begins "In the Java programming language, arrays are objects (§4.3.1), are dynamically created, and may be assigned to variables of type Object (§4.3.2). All methods of class Object may be invoked on an array."
My point was that even if Java treats arrays as objects, the fact that every non-OO language has arrays means that arrays in general are not necessarily objects, and using arrays isn't necessarily Object-Oriented. Plus, at a practical level, if you can't use arrays then what will the "add" method add to?

ah, ok :)
yes, I also had that thought, how to add an item ... without an array it would modify the current value instead of saving an additional new one.

This article has been dead for over six months. Start a new discussion instead.