Solved

java programming

Posted on 2004-09-30
10
214 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
Comment Utility
> 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
Comment Utility
class it can be variable name.

0
 
LVL 6

Assisted Solution

by:expertmb
expertmb earned 125 total points
Comment Utility
0
 
LVL 8

Expert Comment

by:thomas908
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 12

Expert Comment

by:Giant2
Comment Utility
>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
Comment Utility
>class it can be variable name.
wrong comment from me apologize for tht
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now