Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 11th, 2005, 11:33 PM   #1
357mag
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 148
Rep Power: 4 357mag is on a distinguished road
A few questions

I've done some console programming in C++ and some GUI programming in Visual Basic. I've found I've been able to mostly understand the programs I've been asked to write using my books. I've most recently tried Java and found it to be hard. For example to write a program that inputs two integers and outputs their sum I had to do this:

import java.io.*;

public class Addup
{
static public void main(String args[])
{
InputStreamReader stdin =
new InputStreamReader(System.in);
BufferedReader console =
new BufferedReader(stdin);
int i1 = 0,i2 = 0;
String s1,s2;
try
{
System.out.print("Enter first number ");
s1 = console.readLine();
i1 = Integer.parseInt(s1);
System.out.print("Enter second number ");
s2 = console.readLine();
i2 = Integer.parseInt(s2);
}
catch(IOException ioex)
{
System.out.println("Input error");
System.exit(1);
}
catch(NumberFormatException nfex)
{
System.out.println("\"" +
nfex.getMessage() +
"\" is not numeric");
System.exit(1);
}
System.out.println(i1 + " + " +
i2 + " = " + (i1+i2));
System.exit(0);
}
}


Now this is totally beyond me. My books don't explain how to write a program like this, only the Deitel book explains how but they're using GUI components like input boxes and such. Which is okay I guess but I was simply curious as to how you could get input from the console window. So I did a search on the internet and that is the code I found. Pretty complicated.

To write the same program in C# what would it be like? Can you write it using GUI components and just using console input?

Interested to find out.
357mag is offline   Reply With Quote
Old Apr 12th, 2005, 1:39 AM   #2
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
java is a little more strict when it comes to OOP and you pay for all the benefits of the language when it comes to things like this. it forces you to understand what is going on rather than just having the magical "cin" and "cout". i assume any c# code would be very similar but IR is the resident expert on that language. but yeah, it sucks donkey balls when all you wanna do is take a damn number and spit it back out. BTW that's fairly simple java code and when you think about it and the death-grip on OOP that the language has you'll understand everything a lot better.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Apr 12th, 2005, 7:12 PM   #3
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
I'd take that over C++ any day of the week...

As for C#:

It would look almost identical to what you have, be it Mono or Microsoft C#. Now the difference would mostly lie in the names. Many of the names are the same between Java and the .Net/Mono languages. I would expect it to be almost compileable if you replaced "NumberFormatException" with "FormatException" and some others. The main difference I see is that rather than all the useless stuff at the top, you would use Console.Readline and Console.Writeline. It is obvious that MS copies Sun on the whole .Net thing. Blatantly.
Dameon is offline   Reply With Quote
Old Apr 13th, 2005, 12:46 AM   #4
357mag
Hobbyist Programmer
 
Join Date: Mar 2005
Posts: 148
Rep Power: 4 357mag is on a distinguished road
Actually for a beginner like me who has not really studied objects or classes or "creating instances of the class" in gets complicated. I'm thinking of returning to console programming in C++ for awhile. When your in Java your up against objects and classes right away, and I'm dubious about whether that's a good idea if you haven't studied the stuff in C++ first.
357mag is offline   Reply With Quote
Old Apr 13th, 2005, 1:00 AM   #5
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
you make a good point, java does kind of force you a little more into the OOP world whearas you can program C++ procedurally all day long.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:54 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC