Simple Explanation about the scala HelloWorld

object HelloScala{

  //1.def represents a method, which is a key

  //2.main name representation, express entry program execution

  //3.args:Array[String] represents a parameter. Scala features: EDITORIAL parameter name, type written on the back (go is the same language, java language, type the former name of the parameter after)

  //4.Array[String] represents an array type

  //5.Unit= indicates that the function returns null value (void similar in java)

  //6.println("Hello,scala ") output

  def main(args:Array[String]):Unit={

    println("Hello,scala")

  }

}

 

//1.object represents a companion objects

//2.HelloScala is the name of the object, which corresponds to the underlying real name is HelloScala $ class, the object is HelloScala $ type of a static object MODULE $

// 3. When we write the object HelloScala a bottom generates two .class files are HelloScala and HelloScala $

//4.scala when running, process is as follows

// (1) start with the main HelloScala started

//public static void main(String[] paramArrayOfString){

//  Predef$.MODULE$.main( paramArrayOfString);

//}

// method (2) and then call HelloScala $ class HelloScala $ .MODULE $ .main

@ (3) The following code is executed

//public void main(String[] args){

//  Predef..MODULE$.println("Hello,scala");

//}

 

// scala considered static and non-static two things

// So it is written into the non-static class {name} to go, it is written into the static object name (and class of the same name) {} to go

 

-------------------------------------------------------------------------------------------------------------

If I write a java HelloWorld

public class HelloWorld{

  public static void main(String[] args){

    System.out.println("HelloWorld");

  }

}

I cmd with scala HelloWorld: run

But I want to run java HelloScala: Sorry, can not run

This can be seen, there is a relationship between the compiler includes (not all inclusive), since there scala library package for java class. Scala draw in the introduction.

 

Guess you like

Origin www.cnblogs.com/fishperson/p/11072818.html