![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#3 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Mar 2005
Posts: 148
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|