Results 1 to 7 of 7
Thread: java basics
- 11-12-2012, 08:35 PM #1
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
java basics
Why should we create an object? what is a need of it? Apart from access members of a class i want what is a need of object what does it contain?? In normal class to access any member of that class we create object where as for static class we access its members using class name. what is a difference between them. iknow we can create an object for static class but no use of it. thanks in advance.
- 11-13-2012, 01:47 AM #2
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Re: java basics
Hi, I'm sorry to all the others that I replied 1st....
Objects are required to interact in a program with other objects or else the program does f**k all. You should read the very 1st few chapters of your java course to realize this. Static classes are available for all to use within the defined package. You deffo need to re-read your course materials m8 before posting nonsense like this - Please re-read your intro course books then come back to us with questions about static class objects and the likes.
Moderator - change as necessary.
- 11-13-2012, 09:41 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: java basics
Put another way, Java is an Object Oriented language.
It's written based on that concept.
If you don't want to use objects then pick a non-OO language as it will probably do a better job.
Now, as for why you should be using OO instead of, say, straight procedural, then there are plenty of articles out there that can explain this in details. It essentially boils down to it being easier to maintain and write code that is structured such that its data and methods sit together in nice little units (classes/objects) and that those units can be extended such that you don't have to copy code between these nice little units (inheritance).
Writing straight into classes using static methods and data can give you the first bit, but not the second.Please do not ask for code as refusal often offends.
- 11-13-2012, 11:17 AM #4
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: java basics
- 11-13-2012, 11:24 AM #5
Member
- Join Date
- Oct 2012
- Posts
- 5
- Rep Power
- 0
Re: java basics
thanks a lott for ur answer.but i have one more doubt, instead of creating object cant we use class name directly to access its members.(classname.member)
and what object contains?
is object a reference variable?
- 11-13-2012, 12:28 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: java basics
Objects contain their attributes.
Some of those attributes may be references to other objects on the heap.
You can use ClassName.member, if 'member' is static. Which, of course, means you can only have one 'ClassName.member' in your application.Please do not ask for code as refusal often offends.
- 11-13-2012, 12:43 PM #7
Member
- Join Date
- Mar 2012
- Posts
- 88
- Rep Power
- 0
Re: java basics
Hi,
Yes I was a bit harsh there in hindsight and I apologise for that. No questions asked on these forums are nonsense of course - how else do you learn? Tolls answer is much more constructive and informative. Creating objects and using them and making them interact is the fundamental principle of Object Oriented Programming.
Thanks
Similar Threads
-
I need help with java basics, a little confused thats all
By bluecognit in forum New To JavaReplies: 1Last Post: 06-29-2012, 12:32 AM -
basics of java
By kmd prasadNaidu in forum New To JavaReplies: 5Last Post: 12-27-2011, 03:42 PM -
Anyone willing to help me with Java basics?
By Rocketz in forum New To JavaReplies: 7Last Post: 02-23-2011, 04:30 AM -
What loop? Java Networking Basics
By JonnySnip3r in forum NetworkingReplies: 0Last Post: 01-28-2010, 08:37 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks