Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6596991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:09:04+00:00 2026-05-25T18:09:04+00:00

Java Day 1 from c#. Just playing around with java (just for fun) and

  • 0

Java Day 1 from c#.
Just playing around with java (just for fun) and thought this example was interesting, the thing that gets me is how does bubblesort method access intArray? ok I know its being passed as a variable.. but its modifying the original array? I could understand of the bubblesort method printed the new array, but its the original method? Cool, but now sure how/why this is allowed? (hope I explained this properly)

public class HelloWorld {

public static void main(String[] args) {

    //create an int array we want to sort using bubble sort algorithm
    int intArray[] = new int[]{5,90,35,45,150,3};

    //print array before sorting using bubble sort algorithm
    System.out.println("Array Before Bubble Sort");
    for(int i=0; i < intArray.length; i++)
        System.out.print(intArray[i] + " ");

    //sort an array in descending order using bubble sort algorithm
    bubbleSort(intArray);

    System.out.println("");

    //print array after sorting using bubble sort algorithm
    System.out.println("Array After Bubble Sort");
    for(int i=0; i < intArray.length; i++)
        System.out.print(intArray[i] + " ");

    }

    private static void bubbleSort(int[] intArray){

    int n = intArray.length;
    int temp = 0;

    for(int i=0; i < n; i++){
        for(int j=1; j < (n-i); j++){

            if(intArray[j-1] < intArray[j]){
                //swap the elements!
                temp = intArray[j-1];
                intArray[j-1] = intArray[j];
                intArray[j] = temp;
            }
        }
    }        
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:09:04+00:00Added an answer on May 25, 2026 at 6:09 pm

    Arrays are object types in Java, and so are accessed by reference. You pass a reference* to the original array when you call the method, so the method accesses (and modifies) the original array.


    * To all the sharp-eyed pedants, I’m being very careful to avoid the “you pass by reference in Java” fallacy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

G'Day Programmers, I am from Java background however I have just started learning C++
We have 50+ Java batch processes that run at different times of the day.
(Java question) If I reference a field in an inner class, does this cause
Sorry if this sounds like a newbie question, but the other day a Java
Good day! Is it possible to create mobile games or services just knowing Java
I'm just transitioning from .NET to JAVA and have to start JAVA project with
My Java web application (tomcat) gets all of its data from an SQL database.
How to get the name of the day from java sql.Timestamp object such as
I was writing a toString() for a class in Java the other day by
The other day I decided to write an implementation of radix sort in Java.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.