0% found this document useful (0 votes)
4 views7 pages

Java Course Udemy

The document outlines a Java course focusing on using JShell, a Java REPL tool. It covers various commands and functionalities such as checking Java and JShell versions, printing outputs, assigning variables, creating methods, and performing operations like generating multiplication tables and checking odd/even numbers. Additionally, it includes topics on method overloading and saving commands to a file.

Uploaded by

jolie.swathika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Java Course Udemy

The document outlines a Java course focusing on using JShell, a Java REPL tool. It covers various commands and functionalities such as checking Java and JShell versions, printing outputs, assigning variables, creating methods, and performing operations like generating multiplication tables and checking odd/even numbers. Additionally, it includes topics on method overloading and saving commands to a file.

Uploaded by

jolie.swathika
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

JAVA COURSE

CONTENT:
WORKING IN JSHELL:
1)To check JAVA version
2)To check jshell version
3)INTRODUCTION TO JSHELL
4) TO PRINT OUTPUTS
5) IN BUILT METHODS
6) Assigning a variable
7) PRINTF in jshell
8) Printf.Println()
9) To search inside jshell
10) TO CREATE A MULTIPLICATION TABLE FOR 7
11) TO OUTPUT 10 TO 1
12) TO CHECK ODD AND EVEN NUMBERS FROM 1 TO 10
13) METHODS
14) TO LIST ALL METHODS IN JAVA
15) TO BACKUP ALL COMMANDS IN A FILE
16) TO EDIT A METHOD IN JSHELL EDITOR

1.TO CHECK JAVA VERSION:


java -version
java version "21.0.2" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 21.0.2+13-LTS-58)

1
Java HotSpot(TM) 64-Bit Server VM (build 21.0.2+13-LTS-58, mixed mode,
sharing)

2.TO CHECK JSHELL VERSION:


C:\Users\swath>jshell -version
jshell 21.0.2

3.INTRODUCTION TO JSHELL:
JSHELL ->is Java REPL(Read,evaluate,print,loop)
C:\Users\swath>jshell
| Welcome to JShell -- Version 21.0.2
| For an introduction type: /help intro
jshell> /help intro
jshell> /exit
| Goodbye

4.TO PRINT OUTPUTS:


jshell> System.out.println("Hello\nworld")
Hello
world
jshell> System.out.println("Hello\"world")
Hello"world
jshell> System.out.println("Hello\\world")
Hello\world
jshell> System.out.println("Hello\\\\\\")
Hello\\\
jshell> System.out.println("H\tw")
H w

5.IN BUILT METHODS:

2
jshell> Math.random() //accepts no parameter
$8 ==> 0.47679479843234707
jshell> Math.min(8.9,8.8)
$10 ==> 8.8
jshell> Math.max(8.9,8.8)
$11 ==> 8.9

6.ASSIGNING A VARIABLE:
jshell> int i = 0
i ==> 0
jshell> int newVar //automatically takes
up value as 0
newVar ==> 0

7.PRINTF IN JSHELL:
jshell> System.out.printf(2)
| Error:
| no suitable method found for printf(int)
| method java.io.PrintStream.printf(java.lang.String,java.lang.Object...)
is not applicable
| (argument mismatch; int cannot be converted to java.lang.String)
| method
java.io.PrintStream.printf(java.util.Locale,java.lang.String,java.lang.Object.
..) is not applicable
| (argument mismatch; int cannot be converted to java.util.Locale)
| System.out.printf(2)
| ^---------------^
jshell> System.out.printf("2") //printf can only
take string
2$15 ==> java.io.PrintStream@6d7b4f4c

8.PRINTF.PRINTLN();

3
jshell> System.out.printf("2").println()
2
jshell> System.out.printf("%d > %d",6,5).println() //%d is for
integers
6>5
System.out.printf("%f %d",7.4,8).println() //%f is for
float
7.400000 8
jshell> System.out.printf("%s","test").println() //%s is for
string
test

9.TO SEARCH INSIDE JSHELL:


jshell> ctrl + r – to search for things inside jshell

10.TO CREATE A MULTIPLICATION TABLE FOR 7:


jshell>int table = 7;
jshell> for(int i = 0;i<=10;i++){
...> System.out.printf("%d * %d = %d",table,i,table*i).println();}
7*0=0
7*1=7
7 * 2 = 14
7 * 3 = 21
7 * 4 = 28
7 * 5 = 35
7 * 6 = 42
7 * 7 = 49
7 * 8 = 56
7 * 9 = 63
7 * 10 = 70

4
11.TO OUTPUT 10 TO 1:
jshell> for(i = 10;i>=1;i--){
...> System.out.println(i);}
10
9
8
7
6
5
4
3
2
1

12.TO CHECK ODD AND EVEN NUMBERS FROM 1 TO 10:


jshell> int even = 0
even ==> 0
jshell> for(int even = 0; even < 11; even++){
...> if(even % 2 == 0){
...> System.out.printf("%d is even",even).println();}
...> else{
...> System.out.printf("%d is odd",even).println();}}
0 is even
1 is odd
2 is even
3 is odd
4 is even
5 is odd
6 is even
7 is odd

5
8 is even
9 is odd
10 is even

13.METHODS:
jshell> void sayHelloWorldThrice(){
...> System.out.println("Hello World");
...> System.out.println("Hello World");
...> System.out.println("Hello World");
...> }
| created method sayHelloWorldThrice()

jshell> sayHelloWorldThrice()
Hello World
Hello World
Hello World

jshell> void sayHelloWorldThrice(){


...> System.out.println("I have created my first variabvle");
...> System.out.println("Loop here");
...> System.out.println("Java");
...> }
| modified method sayHelloWorldThrice()

jshell> sayHelloWorldThrice()
I have created my first variabvle
Loop here
Java

14.TO LIST AVAILABLE METHODS IN JAVA:

6
jshell> /methods
| void sayHelloWorldThrice()

15.TO BACKUP ALL COMMANDS IN A FILE:


jshell> /save backup.txt

16.TO EDIT A METHOD IN JSHELL EDITOR:


jshell> /edit sayHelloWorldThrice
| modified method sayHelloWorldThrice()

17.TO PRINT THE CODE INSIDE THE METHOD:


/list methodname

18.METHODS WITH ARGUMENTS:


void noOfPages(int pages){
System.out.println(pages);
}

19.METHOD OVERLOADING:
Method Overloading - you have two different methods with same name
but different parameter
From a method u can only return one argument, be it u can pass any
no.of.arguments.

You might also like