Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

java programming

Posted on 2004-09-30
10
Medium Priority
?
256 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
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 375 total points
ID: 12196988
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 375 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

927 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