Java Understanding Array Initialization in JavaScript

  • Thread starter Thread starter AllenHe
  • Start date Start date
  • Tags Tags
    Javascript
AI Thread Summary
Creating an array in programming involves using a syntax that may initially seem confusing, particularly regarding the naming conventions. The general form is to declare an array variable and then instantiate it, which can lead to the impression that the array name is repeated unnecessarily. For example, the statement "MyArray myArray = new MyArray();" illustrates that "MyArray" is the class type, while "myArray" is the instance of that class. This distinction is crucial because the instance must be assigned a value before it can be utilized. Therefore, variables like myArray1, myArray2, and myArray3 must be initialized with "new MyArray()" before they can be used in the program. Understanding this initialization process is essential for effective array management in coding.
AllenHe
Messages
74
Reaction score
0
The general form for creating an array is:

Myarray=new arrayname();

But I don't understand wht should I type in the name of the array twice? Because I thought Myarray and arrayname is the same.
 
Technology news on Phys.org
DO you really mean something like this:

MyArray myArray = new MyArray();

where MyArray is a class and myArray is an instance?

The statement above creates an instance called myArray of type MyArray. This is how you initialize myArray rather like assigning a value to it.

MyArray myArray1;
MyArray myArray2;
MyArray myArray3;you can't use myArray1, myArray2, or myArray3 until you've assigned them a value that is until you do this:

myArray1 = new MyArray();
myArray2 = new MyArray();
myArray3 = new MyArray();

hope this helps.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Back
Top