3 Replies - 359 Views - Last Post: 10 April 2012 - 10:30 AM Rate Topic: -----

#1 piyush_j2005  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-March 12

what is a class?

Posted 10 April 2012 - 03:36 AM

what is a class?
Is This A Good Question/Topic? 0
  • +

Replies To: what is a class?

#2 Macjohn  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 80
  • View blog
  • Posts: 407
  • Joined: 10-April 09

Re: what is a class?

Posted 10 April 2012 - 03:53 AM

Classes are the fundamental building blocks of a Java program. You can define an Employee class as follows:

class Employee {
  int age;

  double salary;
}


By convention, class names capitalize the initial of each word.
For example: Employee, Boss, DateUtility, PostOffice, RegularRateCalculator.
This type of naming convention is known as Pascal naming convention.
The other convention, the camel naming convention, capitalize the initial of each word, except the first word.
Method and field names use the camel naming convention.

You can read more about it HERE

Or go HERE to see some resource threads by some of "us" here in DIC
Was This Post Helpful? 2
  • +
  • -

#3 karabasf  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 202
  • View blog
  • Posts: 417
  • Joined: 29-August 10

Re: what is a class?

Posted 10 April 2012 - 10:03 AM

One way to visualize a class is to see it as an abstraction of a real life object. Classes in Java can store data, but can also describe the behaviour of the object itself.

Take a car for example (the ones who're already familiar with my explanation, yes I am always using a car), a car has certain properties, like the amount of fuel it can store, the color, amount of passengers, etc. But a car can also drive, brake and idle.

In short:
- In Java the car would be an object
- The properties of the car would be the properties of the object
- The behaviour of the car would be described by the methods of the objects

By conventions:
- Class names are Pascal typed (see post above) and are always nouns
- Methods of the class are camelcased and start with a verb. E.g. getCarColor() (which would retrieve the color of the car)
- Constants are CAPITALIZED
- Variables are camelcased

Obviously, the names should have a meaningful name.

Finally, there are also concepts related with classes such as
- inheritance and
- abstract classes and interfaces

As you can see, a class may look small, but it's use is what makes it powerful in Java.

This post has been edited by karabasf: 10 April 2012 - 10:04 AM

Was This Post Helpful? 2
  • +
  • -

#4 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7744
  • View blog
  • Posts: 13,083
  • Joined: 19-March 11

Re: what is a class?

Posted 10 April 2012 - 10:30 AM

A class, I'm guessing, is where you got this question on your homework assignment. :)
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1