0

I want to create a java class in a script file (javax.script). please help

0

3 Answers 3

2

Have you tried Google?

First 2 results:

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/

http://java.sun.com/javase/6/docs/technotes/guides/scripting/programmer_guide/index.html

Sign up to request clarification or add additional context in comments.

2 Comments

The thing that I want to do is creating a class in the script (in my script file, and use it like a java class) this is all what I need. I don't want to import a class from my project, but I need to create it in the script. how to do ???
The best that you can do is create a Javascript object, cast it to invokable, and do it from there. However unless your doing some kind of plugin system, you are kinda breaking some OOP rules
1
public class WesternTown {

     int stables;
     int saloon;
     int yearEstablished;
     int troublemaker;
     String sheriffsname;
     String location;


     public WesternTown() {
         stables=3;
         location="Wesrtern America";
         yearEstablished=1850;
     }

     public WesternTown(String name) {
         sheriffsname = name;
     } 


     public static void main (String [] args){

         WesternTown newtown = new WesternTown();
         WesternTown newname = new WesternTown("SHERIFFER");
         System.out.println("stables:      " + newtown.stables);
         System.out.println("saloon:       " + newtown.saloon );
         System.out.println("sheriffs:     " + newtown.sheriffsname ); 
         System.out.println("troublemaker: " + newtown.troublemaker );
         System.out.println("location:     " + newtown.location );
         System.out.println("yearEstablished: " + newtown.yearEstablished );
         System.out.println("The Name is:     " + newname.sheriffsname );
     }
}

Comments

1
import java.io.*;
public class Employee{
 String name;
 int age;
 String designation;
 double salary;

 public Employee (String name){
  this.name=name;
 } 
 public void empAge(int empAge){
  age=empAge;
 }
 public void empDesignation(String empDesig){
  designation=empDesig;
 }
 public void empSalary(double empSalary){
  salary=empSalary;
  }
 public void printEmployee(){
  System.out.println("Name:         "+name);
  System.out.println("Age:          "+age);
  System.out.println("Designation:  "+designation);
  System.out.println("Salary:       "+salary);

 }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.