Jesper de Jong wrote:
Will Zelan wrote:
Jesper de Jong wrote:
Will Zelan wrote:i had doubt in 14 and 22 nd line,i know it is the method which do some functions,in 14th line what are passing and 22nd line what is inta[] and int n can you tell me
What do you think the answer to that question is yourself?
passing the parameter as array and array length in 14th line,will you tell me
Exactly, it's just a method call like any other method call, where parameters are passed. Nothing special going on.
Will Zelan wrote:why passing array.length in 14th line
and what about 22nd line int [] and int n
Jeff Verdegan wrote:
Will Zelan wrote:why passing array.length in 14th line
Look at the method being called to see how it's used.
and what about 22nd line int [] and int n
What about it?
Will Zelan wrote:
passing parameter to method i understand, so we are passing array,is it need to pass arraylength also?
Jeff Verdegan wrote:
Will Zelan wrote:
passing parameter to method i understand, so we are passing array,is it need to pass arraylength also?
Look at how the method uses that parameter. Work through what it would do if that parameter were less than the array length.
Will Zelan wrote:
in the above code i just mention int n=array.length,but why it cant accesible in for loop
Will Zelan wrote:i just modified the program without using array.length in method,i got compile time error
Jesper de Jong wrote:
Will Zelan wrote:i just modified the program without using array.length in method,i got compile time error
What is the error? Compiler error messages contain a lot of useful information that explain what the exact problem is. Don't just say "I got an error", tell us exactly what the error is.
You've removed the parameter n from method bubble_srt. But you're still using n inside the method. The compiler ofcourse doesn't know anymore what n is inside the bubble_srt method.
Jesper de Jong wrote:Variables have a scope. They only exist within that scope. For local variables, the scope is from the point where the variable is declared until the } of the block in which the variable is declared.
You declare a local variable n in line 13. The scope of n is from line 13 to line 21. It doesn't exist outside that range of lines.
Local variables are never visible outside the method inside which they are declared. The local variable n which is declared in the main method is not visible in the bubble_srt method.
No. The variable n only exists inside the other method. The parameter does not access anything. The reference to the array is sent as an argument.Will Zelan wrote: . . . oh ok, so thats why we are passing to method as parameter of variable array and length and again we are accessing those parameters in method as int a[] which is accesing array and int n which acessing length by providing identifier,is my explanation is correct
No.is there any way we can use "this" keyword in the above program
what is argument? is it different from parameter?
Will Zelan wrote:is there any way we can use "this" keyword in the above program
Campbell Ritchie wrote:Always use one of the following idioms for for loops to iterate an array forward:-The latter is officially called the enhanced for loop, though many people call it a for‑each loop and you read the header, “for each Foo f in fooArray.” Note that the loop variable f must be regarded as read‑only. More details in the Java Tutorials and Language Specification, though the latter is often difficult to read.
Campbell Ritchie wrote:
confused,reference to the array is sent as an argument so which is argument in the above programCampbell Ritchie wrote:No. The variable n only exists inside the other method. The parameter does not access anything. The reference to the array is sent as an argument.
Jesper de Jong wrote:There's a subtle difference between parameters and arguments, which is what Campbell tried to show.
A method can have parameters. You specify the parameters in the method declaration. When you call a method, then the actual value(s) that you are passing are the arguments.
Jesper de Jong wrote:It's not actually necessary to pass the length of the array to bubble_srt explicitly, because an array already knows its own length.
Will Zelan wrote:is there any way we can use "this" keyword in the above program
Jesper de Jong wrote:Why would you want to use the "this" keyword in the above program? I don't see why that would apply in any way.
confused,reference to the array is sent as an argument so which is argument in the above programCampbell Ritchie wrote:No. The variable n only exists inside the other method. The parameter does not access anything. The reference to the array is sent as an argument.
Jeff Verdegan wrote:Do you understand the difference between declaring a method and calling a method?
Will Zelan wrote:
Jeff Verdegan wrote:Do you understand the difference between declaring a method and calling a method?
yes, declaring method having variables as a parameters,when the method is calling the values passed to method is called arguments am i correct?
Jeff Verdegan wrote:Do you understand the difference between declaring a method and calling a method?
Will Zelan wrote:yes, declaring method having variables as a parameters,when the method is calling the values passed to method is called arguments am i correct?
Jeff Verdegan wrote:I meant, what does it mean to declare a method? What does a method declaration look like? What does it mean to call a method? What does a method declaration look like?
Can you tell me what method declarations and/or calls you see in this code?
Jesper de Jong wrote:Declaring a method means: putting a new method in a class or interface. The first line of the method is called the method declaration; it tells you what the name of the method is, what its parameters are, what it returns etc. (see Defining Methods in Oracle's Java Tutorial).
Calling a method means: using the method, in other places in your program. When you call a method, you have to supply specific values for the parameters - these values are called the arguments.
The words "parameters" and "arguments" are sometimes used interchangeably. Don't get too much hung up on the exact words.
These are all very basic concepts. Make sure you understand the basics before trying to write more complicated programs, otherwise you'll be overwhelmed.
There are several good books for learning Java, such as Head First Java, and the Oracle Java Tutorials are a good online learning source. Also see the Bunkhouse for book reviews.
sekhar kiran wrote:now the only thing i have to know is which means passing parameters in a method it is clear
,is it correct put semicolon for method
it is also method,but here int a[] and int n are arguments or accesing the parameters of previous method?
Jeff Verdegan wrote:It's correct to put a semicolon at the end of a statement. Often a statement is just a method call, or a method call with an assignment of the result to a variable. But sometimes a method call is embedded as an argument to another method, and sometimes method calls are chained. So we don't always immediately follow a method call with a semicolon.
sekhar kiran wrote:suppose we declar void a(){} here we do not provide any semicolons why?
see the above program tell whats happening 15 and 24,im clear about 15th line
Jeff Verdegan wrote: public void a() {
// do nothing
}
Jeff Verdegan wrote: Is package-private (hence no public, private or protected keyword ,except that it's not public.
Jeff Verdegan wrote:I assume you mean 14 and 23.
I don't know what to say. You've been told exactly what those are several times, and you even claimed you understand it.
Jeff Verdegan wrote:If you don't know what's going on there, then you also don't know what's going on here:
public static void main(String a[])
System.out.println("Values Before the sort:\n");
Jeff Verdegan wrote: It is either part of a method declaration, in which case int a[] and int n are telling us what arguments we'll have to pass when we call that method
its ok thanks for your replyJeff Verdegan wrote:I'm sorry, but I have no idea what you're saying and I have no idea what you're still asking about. Maybe somebody else will be able to help you. Good luck!
sekhar kiran wrote:1)let me clear my doubts,iam very clear about this bubble_srt(array, array.length); it is method declaration with passing arguments if it is correct say yes
2)here it is method call which passing arguments so then only array values and arraylength will be initialized here void bubble_srt( int a[], int n ),if it is correct say yes
3)why some methods have no semicolon(note iam clear about public static void main() and system.out.println():these two methods iam clear so i dont want to interfere here)for example see 1)
sekhar kiran wrote:1)so as your explanataion bubble(array,array.length) it is method call which passing argument for the method declaration void bubble(int a[],int n)
2)passing arguments to a method should be end with semicolon,is it both are correct
Jeff Verdegan wrote:I already explained the rules for where to put a semicolon. Nowhere in those rules is there anything about passing arguments to a method. The rules do mention calling vs. declaring, however.
In all the time you've spent worrying about the details of where to put and not put semicolons, you could have written a lot of code and been learning firsthand. If you forget one, the compiler will let you know.
can you give me some simple example which mentioned above quote ,its very helpful to meJeff Verdegan wrote: it's in a chain and not the final method, or passed as an expression to another method or constructor, or is an operad to an operator and not the final token in its statment
sekhar kiran wrote:the basic thing whenever calling method should be semicolon,am i right
can you give me some simple example which mentioned above quote ,its very helpful to meJeff Verdegan wrote: it's in a chain and not the final method, or passed as an expression to another method or constructor, or is an operad to an operator and not the final token in its statment
compile time error whats the problem
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|