473,785 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java Class definition errors--Pls HELP

2 New Member
Hi Guys,

This is the first time am doing java and i have been struggling to find out whats wrong with this program....when ever i try running it ...it says Java Class Definition error

public class Ex0603
{
public static void main(String[] args)
{
System.out.prin tln("Circles");
showCircle(1.5) ;
showCircle(2);
showCircle(5.7) ;
showCircle(7);
showCircle(25);
}

static void showCircle(doub le r)
{
Circle c = new Circle(r);
String str = "Radius: " + c.getRadius() + "\t"
+ "Area: " + c.getArea() + "\t"
+ "Circumfere nce: " + c.getCircumfere nce();
System.out.prin tln(str);
}
}
class Circle

{
double radius1;

Circle(double r)
{

radius1=r;
}

double getRadius()
{
double rad;
return(rad);
}


double getArea()
{
double Area;
Area=Math.PI*ra dius1*radius1;
return(Area);
}

double getCircumferenc e()
{

double Circumference,r adius;
Circumference=2 * Math.PI * radius1;
return(Circumfe rence);
}

}
Feb 24 '08 #1
5 1251
sukatoa
539 Contributor
you forgot bro....

If your main class is named Ex0603, you should save it as Ex0603.java

And @ this method below,

double getRadius(){
double rad;
return(rad);
}

The JVM won't allow to compile because of the rad, that have not initialized...

If the JVM will allow this, any byte value from the general register DX or Data Register that the system used will be temporarily store at rad...

Then you may experience wrong flow to your code...if it happens

I've test your code and the "double rad" has only the problem....


Correct me if im wrong,
Sukatoa (Shadow Shaman)
Feb 24 '08 #2
rimizin
2 New Member
Hi, I am zeeni.......... .thanks for ur post..........i tried making the changes below........wh at did u mean by initializing... ..u mean i should write double ro=0;? can u check if my code below is right? Also i noticed a strange thing while compiling....de spite i changed the code from int to double radius1 ...my compiler shows Error int radius1........ ......why is it not updating the compilation?


class Circle

{
double radius1;

Circle(double rad)
{
radius1=rad;
}

double getRadius()
{
double ro;
ro= input.nextdoubl e(); //Read radius from user
radius1=ro;
return(radius1) ;
}

double getArea()
{ double area;
area=Math.PI*ra dius1*radius1;
return(area);
}

double getCircumferenc e()
{ double circumference;
circumference=2 * Math.PI * radius1;
return(circumfe rence);
}

}
Feb 24 '08 #3
sukatoa
539 Contributor
Hi, I am zeeni.......... .thanks for ur post..........i tried making the changes below........wh at did u mean by initializing... ..u mean i should write double ro=0;? can u check if my code below is right? Also i noticed a strange thing while compiling....de spite i changed the code from int to double radius1 ...my compiler shows Error int radius1........ ......why is it not updating the compilation?


class Circle

{
double radius1;

Circle(double rad)
{
radius1=rad;
}

double getRadius()
{
double ro;
ro= input.nextdoubl e(); //Read radius from user
radius1=ro;
return(radius1) ;
}

double getArea()
{ double area;
area=Math.PI*ra dius1*radius1;
return(area);
}

double getCircumferenc e()
{ double circumference;
circumference=2 * Math.PI * radius1;
return(circumfe rence);
}

}

I mean,

double getRadius()
{
double rad;
return(rad);
}

If i will call the getRadius() method, thus it returns a real value? what value?
About my previous post, i try it to refer to assembly, Sorry if you couldn't understand some phrase there...

But here is the logic,

If your house is getRadius() and you and your family's surname is rad,

I would like to call you but i don't know your name, just the surname shouting outside your house, rad?!! rad?!! would your parents go outside to find out who's calling? is it for you? is it for your parents?

They don't really know because i call you rad, since that is you surname(Assumin g), so, i must call your name just to catch only your attention and not disturbing the others...

In assembly, we must put every data in a stack in every mov, because, The system always uses those registers priority to there processes...

If JVM let this allow, probably the rad might initialized any of the data being stored in a stack... for example, the system stores a hexadecimal value 0AFF,

and your code needs only a 5 double value, then the flow of your program is incorrect, according to your code, wondering why is it happening...

for example,

int value = double value + int value;

is it correct? JVM doesn't allow this because the range of int is much smaller that a double value... i can't remind, JoshaH knows this...
if this will be allowed, the result value at int value will receive a wrong format of bit...
Feb 24 '08 #4
JosAH
11,448 Recognized Expert MVP
int value = double value + int value;

is it correct? JVM doesn't allow this because the range of int is much smaller that a double value... i can't remind, JoshaH knows this...
if this will be allowed, the result value at int value will receive a wrong format of bit...
I just know where to look it up: in the Java Language Specification:

A narrowing conversion of a floating-point number to an integral type T takes two steps:


In the first step, the floating-point number is converted either to a long, if T is long, or to an int, if T is byte, short, char, or int, as follows:
If the floating-point number is NaN (§4.2.3), the result of the first step of the conversion is an int or long 0.
Otherwise, if the floating-point number is not an infinity, the floating-point value is rounded to an integer value V, rounding toward zero using IEEE 754 round-toward-zero mode (§4.2.3). Then there are two cases:
If T is long, and this integer value can be represented as a long, then the result of the first step is the long value V.
Otherwise, if this integer value can be represented as an int, then the result of the first step is the int value V.
Otherwise, one of the following two cases must be true:
The value must be too small (a negative value of large magnitude or negative infinity), and the result of the first step is the smallest representable value of type int or long.
The value must be too large (a positive value of large magnitude or positive infinity), and the result of the first step is the largest representable value of type int or long.
In the second step:
If T is int or long,the result of the conversion is the result of the first step.
If T is byte, char, or short, the result of the conversion is the result of a narrowing conversion to type T (§5.1.3) of the result of the first step.
Casting a double to a more narrow int is allowed but Java wants you to tell the
compiler explicitly about your intentions; you do that by applying the 'cast' operator:

Expand|Select|Wrap|Line Numbers
  1. int value = (int)(double_value + int_value);
  2.  
kind regards,

Jos
Feb 24 '08 #5
r035198x
13,262 MVP
Just reminding everyone to use code tags when posting code like Jos did above.
Posting code without using code tags actually violates the site's guidelines.
Feb 25 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
4506
by: Shawn | last post by:
I am getting the following error with a Java Applet being served out by IIS over HTTPS/SSL using a Verisign certificate: java.lang.NoClassDefFoundError: javax/help/HelpSetException at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590) at java.lang.Class.getConstructor0(Class.java:1762) at java.lang.Class.newInstance0(Class.java:276) at...
0
1325
by: Bob | last post by:
I'm interested in something of a plugin scheme. I'd like to be able to add classes that implement a particular interface into a project and have them automatically detected and used. For example, let's say I have a web project running inside a servlet container. I create an interface called PageObject. I then write a few classes that implement PageObject. Let's say they're HeaderPageObject, WeatherPageObject and FooterPageObject. I...
4
3427
by: angel | last post by:
A java runtime environment includes jvm and java class (for example classes.zip in sun jre). Of course jython need jvm,but does it need java class. Thanx
1
1781
by: Jianli Shen | last post by:
Hi, I want to implement like this: class A{ int length; class B{ void operate_length_in_A(){
12
5926
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it says: usage: java fit.FitServer host port socketTicket -v verbose I think this is because I do not understand the jython mechanism for inheritance (yet).
1
4546
by: skchonghk | last post by:
Dear all smart experts, I write a simple Java UDF, which should run on DB2 v8 on AIX. But it can't load the Java class. Help ugently needed!! Thanks! I develop and deploy the Java UDF with these steps: 1. Write the java class, compile and make a jar (see below for source). 2. Call SQLJ.REPLACE_JAR ('file:/home/pws01ta/pws01ta1/examples.jar','test',0) 3. call sqlj.refresh_classes() 4. Create the function by running "create function...
4
2790
by: Dan | last post by:
Hi All, I've got a problem with my C++ application that calls a Java class that I've built with GCJ, I can't run it because I get errors: multiple definition of `atexit' first defined here multiple definition of `_onexit' first defined here multiple definition of `__do_sjlj_init'
2
1297
by: prashan.buddhika | last post by:
Hello, I need to access java class in a jar file using a javascript. Is there any way to do this other than using a java applet ? Please help .. Prashan
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2880
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.