How Scala code gets compiled into Java

For last few days i am learning Scala + play framework. Since i have been using Java for long time now, one that always helps is to convert Scala code into Java Code and see what is going on under the hood. I follow these steps
  1. First i create a new Scala File say Contact.scala which has one Scala class like this
    
    class Contact{
       var firstName =""
       private var lastName = ""
    }
    
  2. Then go to the directory that has Contact.Scala and compile it using scalac Contact.scala, The scala compiler will create .class files for every class in that .sclaa file in appropriate package. In my case i have only one class in my Contact.scala so it creates Contact.class
  3. Next use javap Contact and and i can see following output being generated on the command line
    
    Compiled from "Person.scala"
    public class Contact extends java.lang.Object{
        private java.lang.String firstName;
        private java.lang.String lastName;
        public java.lang.String firstName();
        public void firstName_$eq(java.lang.String);
        private java.lang.String lastName();
        private void lastName_$eq(java.lang.String);
        public Contact();
    }
    

2 comments:

  1. great article.....

    If you want to complete your project on time without delay, contact us to confirm. You can get ready-made academic projects here. Our motive is to give you the utmost service. Projects are available for students pursuing BE, BCA, MCA, BSc, Computer science students. To know more visit our site: https://bit.ly/downloadITprojects
    Or contact us at 9829708506

    ReplyDelete