Kids Learning Java
YANG HU
Java is a powerful programming language thats easy to learn and fun to use! Kids learning Java like playing games, this book teaches main Java skills to kids ages 10+ and step-by-step guidance to know coding. By the end of the book kids can create own application and games.
http://en.verejava.com
Copyright 2020 Yang Hu
All rights reserved.
ISBN : 979863862462 0
CONTENTS
.
.
2.1
2.2
3.1
3.2
3.3
3.4
3.5
3.6
3.7
3.8
3.9
3.10
3.11
4.1
4.2
5.1
5.2
5.3
6.1
6.2
7.1
7.2
7.3
8.1
8.2
9.1
9.2
9.3
9.4
9.5
9.6
11.1
11.2
11.3
11.4
12.1
12.2
12.3
12.4
12.5
13.1
13.2
13.3
13.4
14.1
14.2
14.3
14.4
14.5
14.6
JDK and Eclipse Installation
Graphic installation steps please click below link:
http://en.verejava.com/?id=2272887995877
Create First Java Code and then click menu Run -> Run As -> Java Application
HelloWorld
1. Create file: HelloWorld.java in Eclipse
System.out.println(): Print message to the console and then wrap a new line
System.out.print(): Print message to the console,but do not wrap a new line
\t: tab space
main(String[] args): the entry that Program start to execute
public class HelloWorld { public static void main(String[] args) { System. out .println( "Hello Word" ); System. out .print( "Good beginning \t" ); System. out .print( "is the half of the success" ); } } |
Result:
Hello Word
Good beginning is the half of the success
Variable
Variable: a memory area allocated by the system to store data.
1.Create a file : Variable.java
//: comments are not executed by the program
String : is a sequence of characters " " like : "Apple"
public class Variable { public static void main(String[] args) { String basket = "Apple" ; System. out .println(basket); } } |
Run Result:
Apple
2.Replace the value of variable basket from "Apple" to "Orange"
public class Variable { public static void main(String[] args) { String basket = "Apple" ; System. out .println(basket); String basket = "Orange" ; System. out .println(basket); } } |
Run Result:
Apple
Orange
Arithmetic Operator
Arithmetic operation: add +, minus -, multiply *, divisible /
1. Create file: ArithmeticOperator.java in Eclipse
int : An integer type that can hold an a positive or negative non-decimal number.
public class ArithmeticOperator { public static void main(String[] args) { int a = 1; int b = 2; int c = 3; System. out .println(a + b); System. out .println(a - b); System. out .println(a * b); System. out .println(a / b); System. out .println(c % b); //remaind number after a / b } } |
Result:
-1
Method
public class ArithmeticOperator { public static int add( int a, int b){ return a + b; } public static void main(String[] args) { int result = add (4, 2); // call the add method System. out .println(result); result = add (5, 3); System. out .println(result); } } |
Result:
2. Add 3 more methods about - , *, /
public class ArithmeticOperator { public static int add( int a, int b){ return a + b; } public static int sub( int a, int b){ return a - b; } public static int multiply( int a, int b){ return a * b; } public static int divide( int a, int b){ return a / b; } public static void main(String[] args) { int result = add (4, 2); System. out .println(result); //6 result = sub (4, 2); System. out .println(result); //2 result = multiply (4, 2); System. out .println(result); //8 result = divide (4, 2); System. out .println(result); // 2 } } |
Result:
Class
class: is a user defined blueprint or prototype from which objects are created.
class Caculator{ public int add( int a, int b){ return a + b; } public int sub( int a, int b){ return a - b; } public int multiply( int a, int b){ return a * b; } public int divide( int a, int b){ return a / b; } } public class ArithmeticOperator { public static void main(String[] args) { Caculator cal = new Caculator(); int result = cal.add(4, 2); System. out .println(result); //6 result = cal.sub(4, 2); System. out .println(result); //2 result = cal.multiply(4, 2); System. out .println(result); //8 result = cal.divide(4, 2); System. out .println(result); // 2 } } |
Result:
Type Conversion
1. Create a TypeConversion.java
Integer.parseInt(): this is java default method can convert string to integer.
public class TypeConversion { |