473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Java Class definition errors--Pls HELP

Hi Guys,

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

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

static void showCircle(double r)
{
Circle c = new Circle(r);
String str = "Radius: " + c.getRadius() + "\t"
+ "Area: " + c.getArea() + "\t"
+ "Circumference: " + c.getCircumference();
System.out.println(str);
}
}
class Circle

{
double radius1;

Circle(double r)
{

radius1=r;
}

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


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

double getCircumference()
{

double Circumference,radius;
Circumference=2 * Math.PI * radius1;
return(Circumference);
}

}
Feb 24 '08 #1
5 1239
sukatoa
539 512MB
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
Hi, I am zeeni...........thanks for ur post..........i tried making the changes below........what 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....despite 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.nextdouble(); //Read radius from user
radius1=ro;
return(radius1);
}

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

double getCircumference()
{ double circumference;
circumference=2 * Math.PI * radius1;
return(circumference);
}

}
Feb 24 '08 #3
sukatoa
539 512MB
Hi, I am zeeni...........thanks for ur post..........i tried making the changes below........what 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....despite 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.nextdouble(); //Read radius from user
radius1=ro;
return(radius1);
}

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

double getCircumference()
{ double circumference;
circumference=2 * Math.PI * radius1;
return(circumference);
}

}

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(Assuming), 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 Expert 8TB
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 8TB
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
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...
0
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...
4
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
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
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...
1
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...
4
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...
2
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.