C# allows user to implicitly  define variables using var, but in java they have to be defined explicitly.  CodePorting C#2Java Engine allows user to automatically translate C# code to java code by replacing the type var with correct datatype which result in compile able java code.

Following example shows migration of C# var statement in java:

C# Code:

Code
using System;
Code
using System.Collections.Generic;
Code
using System.IO;
Code
namespace CodePorting.Convert.LanguageConstructs.varStatment
Code
{
Code
     public class Test1
Code
    {
Code
        static void Main()
Code
        {
Code
            int d = 2;
Code
            var x = 5 + d;
Code
             var y = 5.5;
Code
             var z = "this is test";
Code
             var myEmployee = new Employee();
Code
             var list = new List();
Code
Code
            for (var xx = 1; x < 10; x++)
Code
                Console.WriteLine(xx);
Code
Code
            using (var file = new StreamReader("C:\\myfile.txt"))
Code
            {
Code
            }
Code
Code
            string[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };
Code
            foreach (var ul in words)
Code
            {
Code
                Console.Write( ul.ToUpper());
Code
            }
Code
Code
        }
Code
    }
Code
         class Employee
Code
         {
Code
         }
Code
}

 

Java Code generated by CodePorting:

Code
package CodePorting.Convert.LanguageConstructs.varStatment;
Code
// ********* THIS FILE IS AUTO PORTED FORM C# USING CODEPORTING.COM *********
Code
import java.util.ArrayList;
Code
import com.codeporting.csharp2java.System.IO.StreamReader;
Code
Code
 public class Test1
Code
{
Code
    static void main() throws Exception
Code
    {
Code
        int d = 2;
Code
        int x = 5 + d;
Code
         double y = 5.5;
Code
         String z = "this is test";
Code
         Employee myEmployee = new Employee();
Code
         ArrayList list = new ArrayList();
Code
Code
        for (int xx = 1; x < 10; x++)
Code
            System.out.write(xx);
Code
Code
        StreamReader file = new StreamReader("C:\\myfile.txt");
Code
        try /*JAVA: was using*/
Code
        {
Code
        }
Code
        finally { if (file != null) file.close(); }
Code
Code
        String[] words = { "aPPLE", "BlUeBeRrY", "cHeRry" };
Code
        for (String ul : words)
Code
        {
Code
            System.out.printf( ul.toUpperCase());
Code
        }
Code
Code
    }
Code
}
Code
class Employee
Code
{
Code
}