• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to respond to a questions  RSS feed

 
M Shu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

You should avoid the keyword static as much as possible. It has its uses but it is often used incorrectly. You should write a main method with one statement in:-
new Foo(...).run(...);
… and the run method should start your application.
If you are in a static context, you cannot access non‑static members of the class. If you call the method method1() from a static method, and there are two instances of the class, which instance should you call it on? Don't know. That is why you must not access non‑static members from a static method. What if there are no instances of the class? How can you call that non‑static method?


This is not the way to reply someone, You can't restrict anyone to what to use and what to not. It's the job of JVM, if that don't restricts then how you can.

Instead of restrictions you should say "this is not according to guidelines." or "Using (......) may cause you in trouble."
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M Shu wrote:. . . This is not the way to reply someone, You can't restrict anyone to what to use and what to not. It's the job of JVM, if that don't restricts then how you can.
No, but when I see somebody giving bad guidance it is my duty to point that out. The JVM cannot guard against badly designed code.
Instead of restrictions you should say "this is not according to guidelines." or "Using (......) may cause you in trouble."
[The keyword static] is often used incorrectly. That is not according to the guidelines for correct object‑oriented programming. Using static incorrectly may will cause you trouble.

You are on the Beginning forum here. Many of the people here have little experience and cannot tell whether they are being given poor advice. It is incumbent on those of us who are more experienced to make sure any advice given is good.
 
M Shu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
M Shu wrote:. . . This is not the way to reply someone, You can't restrict anyone to what to use and what to not. It's the job of JVM, if that don't restricts then how you can.
No, but when I see somebody giving bad guidance it is my duty to point that out. The JVM cannot guard against badly designed code.
Instead of restrictions you should say "this is not according to guidelines." or "Using (......) may cause you in trouble."
[The keyword static] is often used incorrectly. That is not according to the guidelines for correct object‑oriented programming. Using static incorrectly may will cause you trouble.

You are on the Beginning forum here. Many of the people here have little experience and cannot tell whether they are being given poor advice. It is incumbent on those of us who are more experienced to make sure any advice given is good.


Being on any forum does not guarantee about any ones Experience. There are a lot of experienced people who is having more experience than you and me, but if till now, they have not been using this forum, then will you say them that you are newcomer, you don't have experience, or something like that???

Oracle has already made guidelines what MUST be done, and what SHOULD be done. You can't force any "SHOULD" type guideline to to be "MUST" type.

A good programmer's responsibility is to make others aware about guidelines if and only if they(others) are against of it. Otherwise You SHOULD (even I can't force you to MUST) tell them the Problems which MAY be faced in future.

Like if someone uses "Static" incorrectly, JVM will automatically inform them and stop their code until corrected, but if JVM does not restrict, you SHOULD only tell them that it MAY cause problem.(NOT it WILL ...).

Hope you understood now.
 
Henry Wong
author
Sheriff
Posts: 23280
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this is a side discussion, which came from here ...

http://www.coderanch.com/t/666992/java/java/static-method-invocation-static-method

and it seems more about answering questions, I have split it off to here.



Anyway, to add my 2 cents... I would argue that we need to remember that the ranch is an international community. Additionally, everyone is volunteer here, and in many cases, taking time from their very busy day to answer questions. This means that, perhaps, we should try not to be too much of a language, culture, or "terseness" police when it comes to how to answer. IMHO, if you disagree on something as subtle as "must" versus "should", perhaps it would be better to assume the issue is related to language, culture, or just being busy?

Now, on the other hand, if this topic starts to become a discussion regarding the language and / or virtual machines specifications, then feel free to argue the subtle points. In that realm, it is all legalese, and being as pedantic as possible is a good thing...

Henry
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M Shu wrote:It's the job of JVM, if that don't restricts then how you can.
Instead of restrictions you should say "this is not according to guidelines." or "Using (......) may cause you in trouble."
Lets assume JVM is a vehicle and I want to learn how to drive. The company gives me a book of guidelines how to start vehicle, drive, turn on indicators etc. etc. So now I have guidelines and my vehicle. I wish to go to meet a friend of mine. I read all guideline, now I know how to drive, how to turn on and off indicator and all

But while driving I may get turns, traffic, slippery roads, roads full of pits so I need to understand where I should increase speed and where not, where I should toot horn and where not(Near hospital etc). How to hold and how much turn steering so we can cross a dangerous ghat all these stuff guidelines will not tell me. Perhap I may misunderstand guidelines or understand it but not able to implement it practically.

If books, guidelines and JVM were more enough then I don't thing there would have been institutes, video tutorials on youtube and sites like coderanch. There you need someone experienced to guide you(Not spoon feeding like copy paste ), answer you Why this why not that. If that guide or adviser shout at me slow down the vehicle or toot the horn when there is turn and someone crossing the road then I should never mind if he/she usage may, must or will( better to assume the issue is related to language, culture, or just being busy as Henry Wong said). It is for my good. At the end he is helping me without any charge , by taking time from their busy day. Hope not to misunderstand me
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good explanation
But in programming you can do things you cannot do in a car. You can harm 1000000 people simultaneously. You can probably kill more people all at once than in the worst sort of dangerous driving.
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:But in programming you can do things you cannot do in a car
Vice versa , but agreed with last part
 
Liutauras Vilda
Marshal
Posts: 4511
306
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M Shu wrote:This is not the way to reply someone, You can't restrict anyone to what to use and what to not.
I think Campbell gave a very good advice. I don't see where he tried to restrict someone, just warned about the possible consequences, which you may know are very likely.

M Shu wrote:Instead of restrictions you should say "this is not according to guidelines." or "Using (......) may cause you in trouble."
Everyone has its own style in giving answers. There are no such official rule of thumb guidelines which you mentioned in your phrase, those rather being created by communities and their actual experience.

You may also want to read a tutorial, which is called Main Is A Pain (<-- link, click on it) written by one of Ranch's moderator, you can find there bunch of extra useful tips on the same topic.
 
Campbell Ritchie
Sheriff
Posts: 55351
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganish Patil wrote:
Campbell Ritchie wrote:But in programming you can do things you cannot do in a car
Vice versa . . .
Careful. This is a family website
 
Ganish Patil
Ranch Hand
Posts: 529
19
Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Netbeans IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger !
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!