![]() Here, Enter two number from the command line to find the maximum number.ħ1 89 // Enter two number from command lineįor !! Operator Please check Null Safety. package my.programĬompanion object fun main(args: Array) ") Similar to using an Object Declaration, you can define the main function of a Kotlin program using a Companion Object of a class. Package level functions including annotation. ![]() To change the name of the class that contains top-level functions for a particular file, place the following annotation at the top of the file above the package statement: this example, the main class to run would now be my.program.MyApp. In the above example, the main class to run would be my.program.MainKt. When targeting the JVM, the function will be compiled as a static method in a class with a name derived from the filename. Place the above code into a file named Main.kt (this filename is entirely arbitrary) Here is an example of a simple Kotlin "Hello World" program: package my.program Same as Kotlin also provide you different commands.Īll Kotlin programs start at the main function. :/path/to/kotlin/runtime/jar/kotlin-runtime.jar MainKt VersionsĬompile and Run Kotlin Code in Command LineĪs java provide two different commands to compile and run Java code. In order to run the resulting class file using Java, one must include the Kotlin runt-time jar file to the current class path. However if one was to run the class file using $ java MainKt java will throw the following exception: Exception in thread "main" : kotlin/jvm/internal/IntrinsicsĬaused by: : Īt (URLClassLoader.java:381)Īt (ClassLoader.java:424)Īt $AppClassLoader.loadClass(Launcher.java:335)Īt (ClassLoader.java:357) It is worth noting in $ kotlinc Main.kt will output a java class file, in this case MainKt.class (Note the Kt appended to the class name). Kotlin can also be compiled using Maven, using Ant, and using Gradle, or through the command line. Kotlin has a standard IDE plugin for Eclipse and IntelliJ. Kotlin's standard compiler allows it to be compiled both into Java bytecode for the JVM and into JavaScript. Kotlin is also developed with the goal of providing many of the features wanted by Java developers. Kotlin is developed with the goals of being quick to compile, backwards-compatible, very type safe, and 100% interoperable with Java. Kotlin is a statically-typed object-oriented programming language developed by JetBrains primarily targeting the JVM. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |