Tuesday, June 21, 2016

Scala Beginners Issues


1. Compiling / Running  scala from command line just like javac /java

scalac com/PrintMesgObj.scala 
scala -classpath . com.PrintMesgObj

2. Common Errors:

package com

class PrintMsg {

  def main(args: Array[String]) = {
    println("Hello World !!")
  }
}

if you try to run the above code and expect Hello World to be printed, it won't. See the output
surjanrawat$ scalac com/PrintMsg.scala 
surjanrawat$ scala -classpath . com.PrintMsg
java.lang.NoSuchMethodException: com.PrintMsg.main is not static
at scala.reflect.internal.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:68)

Reason: PrintMsg is class and to use this we need to define object of this class.

1.  Define object for PrintMsg
package com

object PrintMesgObj {
   val obj = new PrintMsg
   def main(args:Array[String])= {
     obj.main(args)
   }
}

surjanrawat$ scala -classpath . com.PrintMesgObj surjan
Hello World !!

Common Errors
1. java.lang.NoSuchMethodException: com.PrintMsg.main is not static
at scala.reflect.internal.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:68)

2. scala -classpath . com.PrintMesgObj
java.lang.NoSuchMethodException: com.PrintMesgObj.main([Ljava.lang.String;)

1 comment:

  1. Big data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. big data projects for students But it’s not the amount of data that’s important. Project Center in Chennai It’s what organizations do with the data that matters. Big data can be analyzed for insights that lead to better decisions and strategic business moves.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Corporate TRaining Spring Framework the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai


    The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

    ReplyDelete