Solved

java programming

Posted on 2004-09-30
10
237 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 125 total points
ID: 12196988
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
print map entry 34 72
ForLoop Example 3 52
tomcat administrtor 12 61
Convert from a json string array to a Java object 3 53
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

856 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