Results 1 to 1 of 1
  1. #1
    ruud00000 is offline Member
    Join Date
    Dec 2010
    Posts
    7
    Rep Power
    0

    Default Convert consoleapp from C# to Java?

    I would like to convert folowing simple example C# console application to Java. What are the changes I need to make? Please briefly explain?

    I tried it myself, see below for a full trace... However I end up with a runtime error, see below.

    Thanks!

    Here's how I started:

    1.
    replace using statements by:
    import java.awt.*;
    import java.applet.*;

    2.
    replace namespace statement by package

    3.
    replace string by String

    4.
    replace the constructor including the public String Naam { get; set; } statement by (??) : how?

    private String Naam;

    public KlantType(String naam)
    {
    Naam = naam;
    }

    public void setNaam(String value)
    {
    Naam = value;
    }

    public String getNaam()
    {
    return Naam;
    }

    5.
    replace Console.WriteLine() with System.out.println()

    6.
    Replace the two classes by one (??) : how?

    7.
    replace Main by main

    8.
    replace klantObjectInstance2.Naam = "Pietersen"; with klantObjectInstance2.setNaam("Pietersen");

    9.
    replace System.out.println("Klant 2 : " + klantObjectInstance2.Naam); by two statements (introducing another variable...):
    klantNaam = klantObjectInstance2.getNaam();
    System.out.println("Klant 2 : " + klantNaam);

    and declaring the new variable at the start of the Program - class (just above the main method) : private static String klantNaam;

    This compiles without error however gives the following runtime error : could not find the main class: ConsoleApplication.KlantType. Program will exit.

    The complete Java code that results form this is below. First here's the original C# console application code:

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace ConsoleApplication1
    {
    public class KlantType
    {
    public KlantType(string naam)
    {
    Naam = naam;
    }

    public string Naam { get; set; }
    }

    class Program
    {
    static void Main(string[] args)
    {

    KlantType klantObjectInstance1 = new ConsoleApplication1.KlantType("Janssen");
    KlantType klantObjectInstance2 = klantObjectInstance1;
    klantObjectInstance2.Naam = "Pietersen";

    Console.WriteLine("Waarden na toekenning waarde Pietersen aan eigenschap Naam van instance klant2 van Object Klant");
    Console.WriteLine("Klant 1 : " + klantObjectInstance1.Naam);
    Console.WriteLine("Klant 2 : " + klantObjectInstance2.Naam);
    }
    }
    }

    Here's my Java code:

    package ConsoleApplication1;

    import java.awt.*;
    import java.applet.*;

    public class KlantType
    {
    private String Naam;

    public KlantType(String naam)
    {
    Naam = naam;
    }

    public void setNaam(String value)
    {
    Naam = value;
    }

    public String getNaam()
    {
    return Naam;
    }

    }

    class Program

    {
    private static String klantNaam;

    static void main(String[] args)
    {

    KlantType klantObjectInstance1 = new ConsoleApplication1.KlantType("Janssen");
    KlantType klantObjectInstance2 = klantObjectInstance1;
    klantObjectInstance2.setNaam("Pietersen");

    System.out.println("Waarden na toekenning waarde Pietersen aan eigenschap Naam van instance klant2 van Object Klant");
    klantNaam = klantObjectInstance1.getNaam();
    System.out.println("Klant 1 : " + klantNaam);
    klantNaam = klantObjectInstance2.getNaam();
    System.out.println("Klant 2 : " + klantNaam);
    }
    }
    Last edited by ruud00000; 12-30-2010 at 05:51 PM. Reason: by

Similar Threads

  1. How can I convert java files to exe?
    By manolis_kakou in forum Advanced Java
    Replies: 6
    Last Post: 07-21-2010, 02:56 PM
  2. how to convert * into : using java
    By Ricks in forum New To Java
    Replies: 2
    Last Post: 02-02-2010, 04:57 PM
  3. Library - convert Java to UML
    By johnny in forum Advanced Java
    Replies: 2
    Last Post: 10-22-2009, 04:14 PM
  4. Convert .java to .exe
    By susan in forum New To Java
    Replies: 6
    Last Post: 02-11-2009, 06:47 AM
  5. Convert java to .exe
    By heartysnowy in forum New To Java
    Replies: 13
    Last Post: 11-21-2008, 08:16 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •