By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,433 Members | 776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,433 IT Pros & Developers. It's quick & easy.

C# analog's of Java classes

P: n/a
Is there any resource where someone who is familiar with Java might
find which .NET classes are similar to classes they are familiar with
in Java? For example, I have a project that I'd like to tackle as a
learning project. In Java, I'd subclass the Panel or JPanel class. Is
there someplace where a Java programmer who is learning C# could
quickly find out what the analog for those classes are?

Dec 16 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Import your .java class files into Visual Studio, which will use the JLCA to
translate them to J#.
Now they are .NET classes.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"TomC" wrote:
Is there any resource where someone who is familiar with Java might
find which .NET classes are similar to classes they are familiar with
in Java? For example, I have a project that I'd like to tackle as a
learning project. In Java, I'd subclass the Panel or JPanel class. Is
there someplace where a Java programmer who is learning C# could
quickly find out what the analog for those classes are?

Dec 17 '06 #2

P: n/a
I'm not trying to convert an existing Java application. I'm trying to
learn C#, and I have an idea of something that I'd like to attempt as a
learning project.

I know what I would do if I was writing it in Java, but I don't want to
write it in Java first and then let some tool convert it to .NET. I
want to write it in C#. But to do that, I need some way to figure out
which library classes in .NET would be somewhat analogous to the
library classes that I'd use in Java.

Peter wrote:
Import your .java class files into Visual Studio, which will use the JLCA to
translate them to J#.
Now they are .NET classes.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"TomC" wrote:
Is there any resource where someone who is familiar with Java might
find which .NET classes are similar to classes they are familiar with
in Java? For example, I have a project that I'd like to tackle as a
learning project. In Java, I'd subclass the Panel or JPanel class. Is
there someplace where a Java programmer who is learning C# could
quickly find out what the analog for those classes are?
Dec 17 '06 #3

P: n/a
"TomC" <to*********@bigfoot.comwrote:
>I know what I would do if I was writing it in Java, but I don't want to
write it in Java first and then let some tool convert it to .NET. I
want to write it in C#. But to do that, I need some way to figure out
which library classes in .NET would be somewhat analogous to the
library classes that I'd use in Java.
My impression is that Java likes to use inheritance a heck of a lot,
and .net tends to use it less. Quite commonly you never even inherit
any classes yourself -- you use events instead.

(although if you were writing a component yourself then you do end up
writing more inheritance yourself).

So, it's hard to answer in isolation what is the equivalent of a java
panel. Instead you should describe the problem you're trying to solve,
(and maybe describe how you architected it in java), and then see what
people answer for most typical way to do it in .net.

--
Lucian
Dec 17 '06 #4

P: n/a

Lucian Wischik wrote:
"TomC" <to*********@bigfoot.comwrote:
I know what I would do if I was writing it in Java, but I don't want to
write it in Java first and then let some tool convert it to .NET. I
want to write it in C#. But to do that, I need some way to figure out
which library classes in .NET would be somewhat analogous to the
library classes that I'd use in Java.

My impression is that Java likes to use inheritance a heck of a lot,
and .net tends to use it less. Quite commonly you never even inherit
any classes yourself -- you use events instead.
(although if you were writing a component yourself then you do end up
writing more inheritance yourself).
In this case, I don't see any way to get around using inheritance.
What I want to do is create a custom visual display, so I need to
customize some sort of object that can be displayed visually.
So, it's hard to answer in isolation what is the equivalent of a java
panel. Instead you should describe the problem you're trying to solve,
(and maybe describe how you architected it in java), and then see what
people answer for most typical way to do it in .net.
OK. Here is an idea that is similar to what I want to do, but more
familiar than my project would be.

Imagine that I was creating a virtual checkerboard class. What I'm
trying to do would be similar to creating a class that represents an
individual square on the checkerboard. It needs to have the the
ability to draw on itself, so I can program it to draw things that look
like checkers, chess pieces, and possibly other images within its
border. By tiling them together to create the image of a checkerboard
with the ability to render the correct game pieces.

The logic for the game would be elsewhere. My goal here is to create
the display. In Java, I'd subclass the Panel class, or possibly the
Component class to accomplish this. Now, surely, there is something
similar in C#.

Dec 17 '06 #5

P: n/a
"TomC" <to*********@bigfoot.comwrote:
>In this case, I don't see any way to get around using inheritance.
What I want to do is create a custom visual display, so I need to
customize some sort of object that can be displayed visually.
Right, there are two types of customizations: (1) by the creator of
the application, who normally customizes by adding events instead of
by inheriting; (2) by the middleware/componentware author who creates
new components through inheritance.

Wearing your application-creator hat, you'd plonk down a PictureBox on
your form, one for each square. You'd probably just set its "Image"
property to the image (draughtspiece, chesspiece, blank...). Or you
could override its OnPaint event. That's to say, OnPaint is a list of
method+instance-pointers, and you will make it point to the
ChesspiecePaint method of your MyForm, and your MyForm will contain
the logic for painting it. Maybe you'd use its "tag" property to store
its coordinates or something like that.

Wearing your componentware-author's hate, you'd inherit from
PictureBox and add any properties that you see fit.

>It needs to have the the ability to draw on itself
So the .net/winforms philosophy is that often it's the
application/form that has the ability to draw the unusual controls it
uses, and which has the ability to respond to their clicks. Instead of
the java philosophy where it's normally the control itself that knows
how to paint itself.

--
Lucian
Dec 17 '06 #6

P: n/a
What I was proposing was that after you get your Java classes compiled as
..NET assemblies, it is easy to use tools like Roeder's Reflector to decompile
them into C# source code. This makes the task of comparing how one would
perform the analogous coding in .NET very easy.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"TomC" wrote:
I'm not trying to convert an existing Java application. I'm trying to
learn C#, and I have an idea of something that I'd like to attempt as a
learning project.

I know what I would do if I was writing it in Java, but I don't want to
write it in Java first and then let some tool convert it to .NET. I
want to write it in C#. But to do that, I need some way to figure out
which library classes in .NET would be somewhat analogous to the
library classes that I'd use in Java.

Peter wrote:
Import your .java class files into Visual Studio, which will use the JLCA to
translate them to J#.
Now they are .NET classes.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"TomC" wrote:
Is there any resource where someone who is familiar with Java might
find which .NET classes are similar to classes they are familiar with
in Java? For example, I have a project that I'd like to tackle as a
learning project. In Java, I'd subclass the Panel or JPanel class. Is
there someplace where a Java programmer who is learning C# could
quickly find out what the analog for those classes are?
>
>

Dec 17 '06 #7

P: n/a
Lucian Wischik wrote:
"TomC" <to*********@bigfoot.comwrote:
In this case, I don't see any way to get around using inheritance.
What I want to do is create a custom visual display, so I need to
customize some sort of object that can be displayed visually.

Right, there are two types of customizations: (1) by the creator of
the application, who normally customizes by adding events instead of
by inheriting; (2) by the middleware/componentware author who creates
new components through inheritance.

Wearing your application-creator hat, you'd plonk down a PictureBox on
your form, one for each square. You'd probably just set its "Image"
property to the image (draughtspiece, chesspiece, blank...). Or you
could override its OnPaint event. That's to say, OnPaint is a list of
method+instance-pointers, and you will make it point to the
ChesspiecePaint method of your MyForm, and your MyForm will contain
the logic for painting it. Maybe you'd use its "tag" property to store
its coordinates or something like that.

Wearing your componentware-author's hate, you'd inherit from
PictureBox and add any properties that you see fit.

It needs to have the the ability to draw on itself

So the .net/winforms philosophy is that often it's the
application/form that has the ability to draw the unusual controls it
uses, and which has the ability to respond to their clicks. Instead of
the java philosophy where it's normally the control itself that knows
how to paint itself.

--
Lucian
Thank you!

This is the type of information that I need. What I am planning is
probably more in the middleware category. I want to create a class
that I can reuse in a variety of ways. In one application it might be
a square on a chessboard, in another it might be a square in a in a
Battleship clone, and in a third it might be drawing a giant
mathematical symbol.

The events would be added later.

I can start by looking at the documentation for the PictureBox class.
It is possible that I can even go further up the inheritance chain
since I would not be drawing .gif's or .bmp's but shapes like circles,
squares and other polygons. But at least now I know where to start
looking.

Now, if I could just find site that maps the various Java classes to
their analogous C# classes I could find this stuff myself.

Dec 18 '06 #8

P: n/a
Oh. I'm not familiar with Roeder's Reflector, but I can see where that
could help. Of course, that would mean writing the whole thing in Java
first, and then rewriting it in C#. I really do appreciate the reply,
but it still seems to be an inefficient use of time. Would it make
sense to create HelloWorld in Java, convert it .NET, and then decompile
it just to find out that the equivalent of System.out.println("Hello,
world!"); in C# is System.Console.WriteLine("Hello, world!");?

Again, I really DO appreciate that you've taken the time to reply.
Maybe I'm missing something.

Peter wrote:
What I was proposing was that after you get your Java classes compiled as
.NET assemblies, it is easy to use tools like Roeder's Reflector to decompile
them into C# source code. This makes the task of comparing how one would
perform the analogous coding in .NET very easy.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"TomC" wrote:
I'm not trying to convert an existing Java application. I'm trying to
learn C#, and I have an idea of something that I'd like to attempt as a
learning project.

I know what I would do if I was writing it in Java, but I don't want to
write it in Java first and then let some tool convert it to .NET. I
want to write it in C#. But to do that, I need some way to figure out
which library classes in .NET would be somewhat analogous to the
library classes that I'd use in Java.

Peter wrote:
Import your .java class files into Visual Studio, which will use the JLCA to
translate them to J#.
Now they are .NET classes.
Peter
>
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
>
>
>
>
"TomC" wrote:
>
Is there any resource where someone who is familiar with Java might
find which .NET classes are similar to classes they are familiar with
in Java? For example, I have a project that I'd like to tackle as a
learning project. In Java, I'd subclass the Panel or JPanel class. Is
there someplace where a Java programmer who is learning C# could
quickly find out what the analog for those classes are?
Dec 18 '06 #9

P: n/a
TomC wrote:
Is there any resource where someone who is familiar with Java might
find which .NET classes are similar to classes they are familiar with
in Java? For example, I have a project that I'd like to tackle as a
learning project. In Java, I'd subclass the Panel or JPanel class. Is
there someplace where a Java programmer who is learning C# could
quickly find out what the analog for those classes are?
I am not a GUI guy myself, but:

http://www.thescripts.com/forum/thread237279.html

Arne
Dec 24 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.