Solved

java programming

Posted on 2004-09-30
10
252 Views
Last Modified: 2010-07-27
Please give me difference between class and Class
Can i store non-primitive type of a field ,class in a class?  
0
Comment
Question by:sraveend
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 92

Expert Comment

by:objects
ID: 12196975
> Please give me difference between class and Class

what exactly are you referring to?

> Can i store non-primitive type of a field ,class in a class?

yes

public class A
{
   private B field;
}
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12196980
class it can be variable name.

0
 
LVL 6

Assisted Solution

by:expertmb
expertmb earned 125 total points
ID: 12196988
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:thomas908
ID: 12197388
class is a keyword used to declare a java class.
Class is a inbuild class in java.lang package
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12197427
class  is used in two places
either declaring a class
like
public class A
{
   private B field;
}

or it can be used to get the class object of an object :)
like this
obj.class.getName();

Class is a class in java.lang package
"Instances of the class Class represent classes and interfaces in a running Java application"
0
 
LVL 12

Expert Comment

by:Giant2
ID: 12197573
>class it can be variable name.

NO. It's a java keyword and indicate to declare a class.

Class (with C uppercase) is a particular class used into java program. See here the doc:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html
0
 
LVL 6

Expert Comment

by:expertmb
ID: 12197590
>class it can be variable name.
wrong comment from me apologize for tht
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12197596
>>Can i store non-primitive type of a field ,class in a class?  

Alternatively, if you mean this, then you can

public class A {
    private Class clazz;
}
0
 
LVL 92

Expert Comment

by:objects
ID: 12197649
The member variables (fields) can be of type primitives, or a particular class.
The class java.lang.Class is no different to any other class in this respect.

What the class java.lang.Class provides is details about a particula java class.
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 125 total points
ID: 12198531
Everything in Java is built out of classes (except for primatives).  So a class is just how you build objects in Java.  In otherwords a class is just a synonym for object.

A Class is a special type of object that is used by Java's reflection tools.  An instance of Class contains all of the definition of the object.  It allows you do look at the object at runtime.  For example
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public class Foo
{
   public int a,b,c;
   private double x,y,z;
   public void bar() throws Exception
   {
            Class me=Foo.class;
            //Another way to get this would be:
         //Class me=Class.forName("Foo");

         System.out.println("class "+me.getName());
         Field[] f=me.getFields();
         for (int i=0;i<f.length;i++)
               System.out.println("field "+f[i].getName());
         Method[] m=me.getMethods();
         for (int i=0;i<m.length;i++)
               System.out.println("method "+m[i].getName());
       
         Foo meInstance=(Foo) me.newInstance();   //This is the same as Foo meInstance=new Foo();

   }

   public static void main(String[] args)
   {
        Foo meInstance=new Foo();
        try {
            meInstance.bar();
      } catch (Exception e) {
            e.printStackTrace();
      }
   }
}

Run the above code and see for yourself what it outputs
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

622 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question