Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

java. aim using jdk1.4 on win2k

  Asked By: Aditi    Date: Mar 28    Category: Java    Views: 937
  

i have posted my few codes in java and i am not able to compile the programs.it
shows some errors everytime.

import java.io.*;
class hello{
public static void main(string args[])
system.out.print("hello java");
}
shows that ; is expected dont know why.


2 mport public package java.lang
import public package java.lang.math
class SquareRoot
{
public static void main(string args[])
{
double x=5;
double y;
y=math.sqrt(x);
system.out.println("y="+y);
}
its shows indentifier expected and . expected
3.
Import java.lang.
Public class Employee extends java.lang
{
string employeeName;
string employeeAddress;
public Employee()
{
employeeName="Carol";
employeeAddress="21 Rock st.";
}
public void DisplayDetails()
{
system.out.println("Name of an Employee is"+employeeName);
system.out.println("Address of an employee is"+employeeAddress);
}
public static void main(string args[])
{
Employee employeeObject=new Employee();
employeeObject.displayDetails();
}
}
its shows class or interface expected dont know what is wrong.these are all ex
from tutorial books

pls giude as how to start inital programming as i am familar with systax but
still i feel thats only on paper as i am not able to do it in system.

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Dannon Jones     Answered On: Mar 28


If you have write here as same as you are compiling the program then look at
'system.out.println' you should use 'System.out.println' as you may already
know Class name's first letter should in capital latter.

 
Answer #2    Answered By: Walborgd Fischer     Answered On: Mar 28

i tried ur suggestion but still i am findiong same error and its shows  that ; is
expected in System.out.println and this error i am finding in this particular
Statement only in most of programs  in write.u thnk that i am missing
something.if yes pls tell me.even if put like this also i am getting same error.
System.Out.Println
i have posted my code

import java.io.*;
class hello{
public static  void main(string args[])
System.out.println("hello java","+");
}

 
Answer #3    Answered By: Bradley Evans     Answered On: Mar 28

try this:

import java.io.*;
class hello{
public static  void main(string args[]){
System.out.println("hello java");
}
}

u r supposed to open and close braces for main method..and u r using " , " for
concatation .u shud use "+" operator for joining multiple strings... this works
fine... im also new to java.. just learning java...

 
Answer #4    Answered By: Barak Levi     Answered On: Mar 28

I have tried out all of your given programs, it's all working fine. Only you
need to take care or case sensitivity. I have modified your all programs
that I am writing here please compare it with your once. And you will see
that you are on a right way and just need to take care with sily mistakes.
One more thing there is no need to import  java.lang package  at every Java
program because this are the defalt package of java  its already accessible.



public class  Hello {



public static  void main(String args[]){

System.out.println("Hello" + " " + "Java");

}

}



public class SquareRoot {

public static void  main(String args[]){

double x=5;

double y;

y = Math.sqrt(x);



System.out.println("y = " + y);

}

}



public class Employee{

String employeeName;

String employeeAddress;

public Employee(){

employeeName = "Carol";

employeeAddress = "21 Rock st.";

}

public void displayDetails(){

System.out.println("Name of an Employee is"+employeeName);

System.out.println("Address of an employee is"+employeeAddress);

}

public static void main(String args[]){

Employee employeeObject = new Employee();

employeeObject.displayDetails();

}

}

 
Answer #5    Answered By: Rosalie Holmes     Answered On: Mar 28

import  java.io.*;
class  hello{
> public static  void main(string args[])
> system.out.print("hello java");
> }
shows  that ; is expected dont know why.

You're missing the left bracket for main

> 2 mport public  package java.lang
> import public package  java.lang.math
> class SquareRoot
> {
> public static void  main(string args[])
> {
double  x=5;
> double y;
> y=math.sqrt(x);
> system.out.println("y="+y);
> }
> its shows indentifier expected and . expected

"math" is not a class. "Math" is. case sensitivity is
very important.

> 3.
> Import java.lang.
> Public class Employee extends java.lang
> {
string  employeeName;
> string employeeAddress;
> public Employee()
> {
> employeeName="Carol";
> employeeAddress="21 Rock st.";
> }
> public void DisplayDetails()
> {
> system.out.println("Name of an Employee
> is"+employeeName);
> system.out.println("Address of an employee
> is"+employeeAddress);
> }
> public static void main(string args[])
> {
> Employee employeeObject=new Employee();
> employeeObject.displayDetails();
> }
> }

"string" is not a class. "String" is.

 
Didn't find what you were looking for? Find more on java. aim using jdk1.4 on win2k Or get search suggestion and latest updates.




Tagged: