Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

class vs type

 
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , anyone know the different between class and type ? i very confuse on this two terms ...thank you !
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without trying to be too robust in this explanation...
You may have noticed that in Java, we've sort of two categories of types, also known as data types: there are the 8 primitive data types, and then there's that whole other category of object types.
Concerning the primitive data types, as mentioned there are 8 of them, and you likely won't be seeing any more. The definition of these types are very much part of the Java programming language (and runtime environment). So, you can't create a new one, since you can't change the language (and runtime environment).
Then we have hundreds of object data types that folks are using - things like String, java.awt.Graphics, java.util.LinkedList, and java.text.DecimalFormat. Each of these object data types are defined by a class. You can create a new object data type by simply creating a new class.
So, your confusion regarding the difference between class and type is probably well-based, and might mean that you're understanding the role of classes - they're primarily used to define object data types.
Got it?
[ May 06, 2004: Message edited by: Dirk Schreckmann ]
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , dirk , thks for explanation , yet some confusion here, i read some book mentioned on subtype ...sometimes subclass ...it really make me confuse on these ...can u please clarify this ?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The term type is more general than class. Types in Java include primitive types and reference types - and the reference types include classes and interfaces. So "type" can mean primitive, class, or interface, while "class" means only class. Except that sometimes (often, actually) people say "class" when they really mean a class or interface. Or sometimes, a class, interface, or primitive. As an example, the class Class should really have been called Type, since it can represent interfaces and primitives as well. But Sun screwed up and called it Class, and now there's unnecessary confusion. Too late to change now though.
As for subtype vs. subclass - same idea, but subtype includes interfaces too. So you can't say that List is a subclass of collection (well, you shouldn't anyway) but you can say it's a subtype.
 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, get it , thank dirk and jim for answer....i'm clear with these now ...tq
[ May 07, 2004: Message edited by: Alvin chew ]
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic