473,765 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Benefits using Properties?

I programmed JAVA for a while and starting C#, and was experimenting
with
"Properties ". Question I have, is what is the benefit? JAVA does
not have the concept
of properties, so what is JAVA missing and why is it so great C# has
it? Thanks,

Yin

Sep 8 '07 #1
4 3132
The Java concept of setting and getting class instance and virtual method
values is what is more formally known as "properties ". So, yes, you do have
properties in Java. This makes your main question mute. If you can
understand why a class should hold data that is related to the class
instance, then you understand why properties are an integral part of most
classes. Technically, properties aren't a C#, Java, or any language for
that matter, thing. They are a a basic tenant of Obejct Oriented
Programming.
"Yin99" <ws@ziowave.com wrote in message
news:11******** **************@ 19g2000hsx.goog legroups.com...
>I programmed JAVA for a while and starting C#, and was experimenting
with
"Properties ". Question I have, is what is the benefit? JAVA does
not have the concept
of properties, so what is JAVA missing and why is it so great C# has
it? Thanks,

Yin

Sep 8 '07 #2
On Sat, 08 Sep 2007 11:47:46 -0700, Yin99 <ws@ziowave.com wrote:
>I programmed JAVA for a while and starting C#, and was experimenting
with
"Properties" . Question I have, is what is the benefit? JAVA does
not have the concept
of properties, so what is JAVA missing and why is it so great C# has
it? Thanks,

Yin
C# properties are syntactic sugar - nice to have but not essential.

C#:

widget.Field = 45;
myVariable = widget.Field;

Java

widget.setField (42);
myVariable = widget.getField ();

rossum

Sep 8 '07 #3
It is just syntactic sugar, but then again syntactic sugar is a big part of
any programming language.
I would phrase the question the opposite way: given that most other modern
programming languages (C++/CLI, VB, C#, Python, ...) have properties, why
doesn't Java? Not to mention other basic elements of modern languages:
delegates, events, operator overloading, a preprocessor, and 'ref' parameters
- some of this stuff sure comes in handy.
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, C++, and Java
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
"Yin99" wrote:
I programmed JAVA for a while and starting C#, and was experimenting
with
"Properties ". Question I have, is what is the benefit? JAVA does
not have the concept
of properties, so what is JAVA missing and why is it so great C# has
it? Thanks,

Yin

Sep 9 '07 #4
"Yin99" <ws@ziowave.com wrote in message
news:11******** **************@ 19g2000hsx.goog legroups.com...
>I programmed JAVA for a while and starting C#, and was experimenting
with
"Properties ". Question I have, is what is the benefit? JAVA does
not have the concept
of properties, so what is JAVA missing and why is it so great C# has
it? Thanks,

Yin
As other have pointed out, properties are the C# equivalent of
setter/setter methods.
You could write C# code using the same getter/setter syntax as in Java
if you prefer, but properties improve the readability of the code. Below
are similar classes in Java and in C#.

------------------------------------
//// Java ////
public class Foo
{
private int x = 0;

public int getX() {return x;}
public void setX(int value) {x = value;}
}

//// C# ////

public class Foo
{
private int x = 0;

public int X
{
get {return x;}
set {x = value;}
}
}

-----------------[ setter example ] ----------------
// Java - You call the setter method explicitly
Foo foo = new Foo();
foo.setX(5);

// C# - X looks like a public field,
// but it really calls the setter under the covers
Foo foo = new Foo();
foo.X = 5;

-----------------[ getter example ] ----------------
// Java - You call the getter method explicitly
int x = foo.getX();

// C# - X looks like a public field,
// but it really calls the getter under the covers
int x = foo.X;

-----------------[ += example ] ----------------
// Java : += logic is a bit painful to look at

// add 2 to foo.x
foo.setX(foo.ge tX + 2));

// C# - Under the covers, this is doing the same thing as the java code
foo.X+=2;

-----------------
If you are interested in the underlying functionality try running this
code.
It explicitly shows how the setter/getter are called

using System;

public class Test
{
public static void Main()
{
Foo foo = new Foo();
foo.X = 5;
Console.WriteLi ne("Foo.X:{0}" , foo.X);

foo.X += 2;
Console.WriteLi ne("Foo.X:{0}" , foo.X);
}
}

public class Foo
{
private int x = 0;

public int X
{
get
{
Console.WriteLi ne("Foo.getX:{0 }", x);
return x;
}
set
{
x = value;
Console.WriteLi ne("Foo.setX({0 })", x);
}
}
}

Hope this helps
Bill




Sep 9 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3519
by: jova | last post by:
What are some of the benefits of using a hash table data structure?
0
430
by: Hamed | last post by:
Hello I have employed as a developer in a software company that its team uses FoxPro / VB 6.0 / VC++ 6.0 as the developing tools and newly is going to migrate to VS.NET. There is a project modified that is to upgrade a big, more than 100,000 lines DOS based program developed by FoxPro 2.x to .NET platform. The design is as previous and the implementation will be reprogrammed. As a duty in my job I should find an answer about the
6
5740
by: news | last post by:
I need some concise, easy to grok examples of what .Net (preferably C#.Net) has over just using old ASP or PHP with JavaScript. See, I'm a PHP guy, and while I started server-side scripting with ASP, I hate it. But last year I had the opportunity to work with a company that was developing sites in VB.Net. And I was wowed! The stuff they could do was really nice and impressive, and I got the chance to learn a little about datagrids. Was...
13
3943
by: Stijn Verrept | last post by:
Hi, I need to make a small web-application and was thinking about doing it in ASP.NET. Another developer (which is also network engineer) says it is hazardous to run .NET on his IIS server. He asks me why not do it in CGI which will be much faster and offers more flexibility. I thought ASP.NET was faster but I'm not sure. Can somebody give me concrete benefits of using ASP.NET over CGI (and vice versa). The application will need to...
7
1080
by: Norman Wooten | last post by:
Ok, I currently program in visual basic 5.0 (ouch, i know its old), Classic ASP & VBScript... I am about to make the jump to Visual Studio 2003, yet I have questions.. C#.NET I hear is quite an interesting language.. I thumbed thru some books at the book store and saw some interesting stuff.. like jagged arrays and such (pretty cool).. But does C# really have any benefits over Visual Basic in the NET
6
8800
by: denis | last post by:
What are the benefits of using const functions? How does the compiler interpret const functions? Thanks, Denis
4
4153
by: arrastogi71 | last post by:
Kindly tell me the costs and benefits of using exceptions?
5
3904
by: mclueless | last post by:
Can n e one tell me the benefits of using an MDI form??? In my project (vb6 n access) i have a main form from where the control goes to other forms depending upon what option the user selects. I thought of making MDI form the main form but i fail to understand the benefits of doing so. right now i have a regular form for it and it works fine. so is it advisable to switch over to MDI form or no???
1
2175
by: Critical Skills, Inc. | last post by:
Oracle Advanced Benefits Analyst / Lead Start: 08/15/2004 End: 03/01/2005 Pay Rate: $80 - $85 per hour Job Duties: Must be open to travel. Must have designed and implemented Oracle Advanced Benefits on at least 1 full cycle implementation. Experience with Oracle HR and Payroll a BIG plus. Project is located in NY/NJ. Local candidates or all inclusive rates. Skill Experience Priority Oracle Advanced Benefits (OAB) 3-5...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.