SpencerPark / IJava

A Jupyter kernel for executing Java code.
MIT License
1.07k stars 211 forks source link

how to use ijava claim a class #118

Open lekeeith opened 3 years ago

lekeeith commented 3 years ago

now, i don't konw how to use ijava to complete a class. such as:

public class Puppy{ public Puppy(String name){ //这个构造器仅有一个参数:name System.out.println("小狗的名字是 : " + name ); } public static void main(String[] args){ // 下面的语句将创建一个Puppy对象 Puppy myPuppy = new Puppy( "tommy" ); } }

lekeeith commented 3 years ago

code

now, i don't konw how to use ijava to complete a class.
such as:

public class Puppy{
   public Puppy(String name){
      //这个构造器仅有一个参数:name
      System.out.println("小狗的名字是 : " + name ); 
   }
   public static void main(String[] args){
      // 下面的语句将创建一个Puppy对象
      Puppy myPuppy = new Puppy( "tommy" );
   }
}

in ijava, i don't konw how to deal with it. i can only use as System.out.println(), int a = 100 and so on...

lekeeith commented 3 years ago

in python, i can easy to complete, such as below:

class A:
  def get_value(self):
    return 123

a = A
a.get_value()

i hope i can get the same method in java. at last, thank you!

uhoefel commented 3 years ago

code

now, i don't konw how to use ijava to complete a class.
such as:

public class Puppy{
   public Puppy(String name){
      //这个构造器仅有一个参数:name
      System.out.println("小狗的名字是 : " + name ); 
   }
   public static void main(String[] args){
      // 下面的语句将创建一个Puppy对象
      Puppy myPuppy = new Puppy( "tommy" );
   }
}

in ijava, i don't konw how to deal with it. i can only use as System.out.println(), int a = 100 and so on...

Works for me both for v1.2.0 and v1.3.0. Just put

public class Puppy{
   public Puppy(String name){
      //这个构造器仅有一个参数:name
      System.out.println("小狗的名字是 : " + name ); 
   }
   public static void main(String[] args){
      // 下面的语句将创建一个Puppy对象
      Puppy myPuppy = new Puppy( "tommy" );
   }
}

into one cell and run it.