Thread: Hello world

  1. #1
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007

    Hello world

    Code:
    using System;
    
    namespace ConsoleApplication
    {
    	/// <summary>
    	/// Summary description for Class1.
    	/// </summary>
    	class Class1
    	{
    		static void Main(string[] args)
    		{
    			
    			Console.WriteLine("Hello World");
    
    		}
    	}
    }
    zen

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    .
    Last edited by Troll_King; 11-30-2001 at 11:27 AM.

  3. #3
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    .
    Last edited by Troll_King; 11-30-2001 at 11:28 AM.

  4. #4
    Java
    Guest
    public class ripoff{

    public static void main(string[] args){

    System.out.println("Does this look familiar?");
    }


    }

  5. #5
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    the HORROR!!
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  6. #6
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    you have to do ALL THAT to make a simple hw app?

    do you have to make it all into classes? like Java?

    I like the old-fashioned C/C++ better

    Oskilian

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    lol... Java, I'm sorry, but get your stuff together first and learn how to hide your data in classes... It does indeed look the same... a shame that C# manages to be the better implemented language, isn't it
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > lol... Java, I'm sorry, but get your stuff together first and learn
    > how to hide your data in classes...

    How is their Java example 'not hiding data'? There is no data. It
    is only a function call.

    > It does indeed look the same... a shame that C# manages to
    > be the better implemented language, isn't it

    How is that better implemented?
    Code:
    using System;
    
    class HelloWorld
    {	public static void Main()
    	{	Console.WriteLine("Hello World!");
    	}
    }
    Versus:

    Code:
    class HelloWorld
    {	public static void main( String [] args )
    	{	System.out.println( "Hello World" );
    
    	}
    }
    They're exactly the same except we didn't have a 'using' (ie: 'import').

    Quzah.

  9. #9
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    I'm not talking about "Hello World".

    Create class a;
    Create class b, containing a private member of class a;

    Grant public reading access ( a getA() function ) that
    does not allow modifying private data, allows reading
    it, and does not create a copy of the data, as that is
    not an appropriate solution.

    Try and cry.


    I did implement examples in the last Java vs C++ thread...
    Look them up if you don't want to do this yourself.

    Oh, and an easy one: Create a constant object of class a.
    ( constant means only functions that do not modify class
    data may be called )
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  10. #10
    "The Oldest Member Here" Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,039
    C# is stupid. Why do this when there's java? How the heck do you even pronounce this language anyway?

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It's pronounced "C sharp".

    > Grant public reading access ( a getA() function ) that
    > does not allow modifying private data, allows reading
    > it, and does not create a copy of the data, as that is
    > not an appropriate solution.

    I hate to rain on your parade, but...
    Code:
    class ClassA
    {	private int x;
    	int getX( ) { return x; }
    }
    
    class ClassB extends ClassA
    {
    }
    
    public class MyProggie
    {	public static void main( String[] args )
    	{	ClassB B = new ClassB( );
    		System.out.println( "X = "+ B.getX( ) );
    	}
    }
    but, um... "What seems to be the problem officer?"

    Where's the problem? Please show me what it is I'm not upposed to be able to do here. I seem to be missing what you're saying I can't do. This is Java. This seems to do exactly what you're saying I can't do.

    Quzah.

  12. #12
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    This seems to do exactly what you're saying I can't do.
    I don't know java that well, but I assume B.getX( ) in your println() call will create a temporary (a copy of private int x).
    zen

  13. #13
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I'm pretty sure that any time, in any language, when you use a "get" function, it returns the value, and thus, always makes a copy of it. The only way around that, would be to return a pointer to the actual variable. If you return a pointer to the actual variable, which I'd be surprised if it let you do, since it is protected, then that's the only way I can think it'd work.

    In Java, pretty much everything is a pointer. If you could return a pointer to a protected or private variable, then it really isn't private any more. The whole point of something being private, is so that outside interference doesn't directly access the variable.

    I imagine that if you were actually returning a pointer to the variable, then there would be some required additional overhead to limit access to the variable based on what class is using the variable and what not. In which case, that overhead would probably be (guessing) close to the same "overhead" you'd have by just creating a "copy".

    A lot of speculation on my part, but it seems resonable.

    Quzah.

  14. #14
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    I imagine that if you were actually returning a pointer to the variable, then there would be some required additional overhead to limit access to the variable based on what class is using the variable and what not. In which case, that overhead would probably be (guessing) close to the same "overhead" you'd have by just creating a "copy".
    Yes if you were returning a primitive, but if you were returning a user defined object then returning a pointer would be much more efficient (due to the size of object and the unnecessary copy constructor calls). C++ allows you to return a const reference (or const pointer) and I presume, as this discussion is taking place, that C# can do something similar -

    Code:
    class a
    {
    private:
    	int b;
    public:
    	const int& get()const{return b;}
    	void set(int _b){b=_b;}
    };

    No copy of b will be made and you will not be able to change b without calling the set method (or cheating).
    zen

  15. #15
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    >This is Java. This seems to do exactly what you're saying I can't do.

    Um... please read my post again, it says EXACTLY what to do.
    I was talking of class A and class B having a private member
    of class A. In Java, you cannot return a reference to this
    private ( NON-PRIMITIVE ) member, without giving write access
    to your private parts ( ouch ). You can either return a reference,
    which allows constructs like this:

    MyVariable.GetMyPrivate().ChangeItsValue();

    Which would change the private members value through a
    read-only function. Or you can create a copy and return this,
    so it can still be modified, but you don't have to care. But
    creating a copy of an object ( imagine said object were
    100 MB in size ! ) for each reading access to it is ridiculous.


    Another, maybe easier thing: Create a class A. Create an instance of this class, that cannot be modified in the whole program. In C/C++/C# this is called a constant. In Java, you
    have the final keyword, which is a joke, because only the
    reference is final, not it's object. But then, how could the object
    be final when you cannot define which methods change it and
    which do not...
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The 7 New Wonders of the World
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 36
    Last Post: 12-08-2006, 01:55 PM
  2. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  3. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM
  4. Too much to ask ?
    By deflamol in forum C Programming
    Replies: 2
    Last Post: 05-06-2004, 04:30 PM
  5. No More Technology After World War Three
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 09-20-2001, 07:02 PM