<jupyter_start><jupyter_text>Java 1<jupyter_code>!wget https://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3.0.zip
!unzip ijava-1.3.0.zip
!python install.py --sys-prefix<jupyter_output><empty_output><jupyter_text>Java in Jupyter Notebook Instructions In this notebook introduction, we will be using the Python kernel to run Java. Running Java in Jupyter Notebook1. Using the Python kernel in Jupyter Notebook  Write%%file filename.java before program.  Write%shell!javac main-class-name.java!java file-main-method-class-name in another code block and run both to see console output.2. Using the Java kernel in Jupyter Notebook  Manually change the configuration of the file using a text editor. Example:       {  "nbformat": 4,  "nbformat_minor": 0,  "metadata": {    "colab": {      "name": "Test1.ipynb",      "provenance": [],      "collapsed_sections": []    },    "kernelspec": {      "name": "Python",      "display_name": "Python"    }  },...    Change to: {  "nbformat": 4,  "nbformat_minor": 0,  "metadata": {    "colab": {      "name": "Test1.ipynb",      "provenance": [],      "collapsed_sections": []    },    "kernelspec": {      "name": "Java",      "display_name": "Java"    }  },...    Write!wget https://github.com/SpencerPark/IJava/releases/download/v1.3.0/ijava-1.3.0.zip!unzip ijava-1.3.0.zip!python install.py --sys-prefix  Run the code before running any other cells  Comments<jupyter_code>%%file comments.java
public class comments{
// This is a single-line comment
/*
  This is a multi-line comment.
  You can type multiple lines in it,
  but you cannot put multi-line comments
  inside another multi-line comment.  
*/
}<jupyter_output>Overwriting comments.java<jupyter_text>Printing 1<jupyter_code>%%file HelloWorld.java

/*
  A classical Hello World program in Java.
  This should output:
    Hello World!
  in a normal runtime, but since jupyter notebook was meant for Python, the Java kernel for
  Jupyter does not compile classes of Java and use Python commands together.
*/


public class HelloWorld { // class block
  public static void main(String[]args){ // method block
    System.out.println("Hello World!");
  }
}
#//shell command to compile and run the java program listed above
#// compile into a .class file
#// run the .class file with Java intepreter

%shell
!javac HelloWorld.java 
!java HelloWorld<jupyter_output>Hello World!<jupyter_text>Printing 2<jupyter_code>%%file print2.java
//You can also use the '+' operator to concatenate two strings, numbers, etc. together in a print statement.

public class print2{
  public static void main(String[]args){
    System.out.println("Hello" + " World!");
    System.out.println(2 + 3);
    System.out.println("Hello" + " World! x" + 2);
  }
}
%shell
!javac print2.java
!java print2<jupyter_output>Hello World!
5
Hello World! x2<jupyter_text>Evaluating a expression.Example: (10.5 + 2 * 3) / (45 - 3.5)<jupyter_code>%%file print.java

public class print{
  public static void main(String[]args){
    System.out.println((10.5 + 2 * 3) / (45 - 3.5));
  }
}
%shell
!javac print.java
!java print<jupyter_output>0.39759036144578314<jupyter_text>Challenge 1 What is wrong with the following line of code?You can try run the following line of code<jupyter_code>%%file challenge1.java

public class challenge1{
  public static void main(String[]args){
    System.outpritl("Hello world!)
  }
}
%shell
!javac challenge1.java
!java challenge1<jupyter_output>challenge1.java:4: error: unclosed string literal
    System.outpritl("Hello world!)
                    ^
1 error
Error: Could not find or load main class challenge1
Caused by: java.lang.ClassNotFoundException: challenge1<jupyter_text>Solution     Solution Challenge 1  1. All statements require a semicolon  2. All strings have to have a pair of double quotes  3. Methods of other classes need to be spelt correctly   Correct Code```    public class challenge1 {      public static void main(String[]args) {        System.out.println("Hello world!");      }    }```  Challenge 2 What is wrong with the following line of code?You can try run the following line of code<jupyter_code>%%file challenge2.java

public class challenge2{
  public static void main(String[]args){
    System.out.println("Hello world",3,9);
  }
}
%shell
!javac challenge2.java
!java challenge2<jupyter_output>challenge2.java:4: error: no suitable method found for println(String,int,int)
    System.out.println("Hello world",3,9);
              ^
    method PrintStream.println() is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(boolean) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(char) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(int) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(long) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(float) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(double) is not applicable
      (actual and formal argument lists differ in length)
    method PrintStream.println(char[]) is not applicable
      (actual[...]<jupyter_text>Solution     Solution Challenge 2  1. Values inside of print statements are concatenated together with the '+' operator   Correct Code```    public class challenge2 {      public static void main(String[]args) {        System.out.println("Hello world" + 3 + 9);      }    }```  Try it yourself! Below you can find a code cell. Experiment!<jupyter_code>%%file FILENAME.java
public class FILECLASSNAME {
    public static void main(String[]args){
        
    }
}
%shell
!javac FILENAME.java
!java FILECLASSNAME<jupyter_output>FILENAME.java:1: error: class FILECLASSNAME is public, should be declared in a file named FILECLASSNAME.java
public class FILECLASSNAME {
       ^
1 error
Error: Could not find or load main class FILECLASSNAME
Caused by: java.lang.ClassNotFoundException: FILECLASSNAME
{'fraction_non_alphanumeric': 0.10050414701577493, 'fraction_numerical': 0.017401203447715077, 'mean_word_length': 3.92, 'pattern_counts': {'":': 20, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '600089', 'license': 'MIT', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1834, 'n_words': 626, 'path': 'Java_1.ipynb', 'repo_name': 'JC-ProgJava/Java-Tutorial', 'size': '6149'}