0

Following Scala code in Azure Synapse should print: Hello, World!. But instead, it prints: defined object Geeks.

Question: What could be the issue and how can we fix it?

object Geeks { 

// Main method 
def main(args: Array[String]) 
{   
    // prints Hello, Geeks! 
    println("Hello, World!") 
} 
}

UPDATE:

I encounter the exact same issue when I run the above notebook in Databricks Community edition from Databricks company.

2
  • Can you clarify how you run this code in Azure Synapse? A notebook? Commented Jul 14, 2024 at 7:12
  • @GaëlJ, That's correct. A notebook. After reading your comment, I have also just added an UPDATE section - just in case. Commented Jul 14, 2024 at 15:53

1 Answer 1

2

When you define an object with a main method in a notebook, the object is compiled and loaded into memory, but the main method is not automatically executed. To execute the main method, you need to call it explicitly outside of the object definition. Below is the way to call the main function inside the object,

Geeks.main(Array())

Here, I gave an empty array value as it doesnot have any impact for this code. You can pass the required arguments while calling different objects.

Sign up to request clarification or add additional context in comments.

2 Comments

Nicely explained. It worked - thank you.
@NaveenSharma Oops!!. I forgot to accept his solution - although I had given him +1. Thank you for reminding me - it indeed helps the SO community, and we should all do it when it resolves the issue described in the post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.