By GokiSoft.com| 15:46 05/09/2022|
Java Basic

[Source Code] Tạo dự án Hello World & Tìm hiểu Scanner trong Java - C2109I



Nội dung học:
	- Hiểu về C, Java -> Bản chất chút
	- Cài đặt môi trường
	- Tạo dự án sample
	- Deploy dự án
	- Kiến thức cơ bản trong Java
		- Kiểu dữ liệu trong Java
		- Khai báo biến
		- Toán tử
		- Mệnh đề điều kiện (if, else, switch)
		- Loop
==============================================================================
1) Câu hỏi: Viết code -> Làm sao máy tính hiểu -> Thực thi được theo ý đồ của chúng ta

- Ngôn ngữ tự nhiên: Con người nc vs nhau
- Ngôn ngữ máy: nhị phân -> 101010101 (Tín hiệu điện) -> Máy tính nó hiểu
- Ngôn ngữ lập trình (C, Pascal, C++, Java, ...)

C -> DevC (IDE: Editor, Compiler) -> Biên dịch -> Mã máy -> Máy tính sẽ hiểu và chạy đc.
Java -> IDE (Eclipse, Netbean, ...) -> Biên dịch -> byecode (jar) -> jvm (Java Virtual Mechine) -> Biên dịch -> Nhị phân -> Máy tính mới hiểu và chạy đc

2) Cài đặt môi trường
	- IDE: Netbean
	- JDK
		8.0
		11
		17
		18




#Test03.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gokisoft.c2109i;

/**
 *
 * @author Diep.Tran
 */
public class Test03 {
    public void test() {
        System.out.println("OKOK");
    }
}


#Test02.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gokisoft.c2109i;

/**
 *
 * @author Diep.Tran
 */
public class Test02 {
    public static void main(String[] args) {
        System.out.println("Test02 xin chao");
    }
}


#Test01.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gokisoft.c2109i;

/**
 *
 * @author Diep.Tran
 */
public class Test01 {
    public static void main(String[] args) {
        System.out.println("Test01 xin chao");
        int x = 5;
        int y = x++;//y = 5, x = 6
//        int t = ++x;
        //x = x + 1; x += 1; x++; ++x;
        System.out.println("x = " + x + ", y = " + y);
        
        int k = x++ + ++y;
        //k = 6(x=7) + (y=6)6 = 12
        System.out.println("x = " + x + ", y = " + y + ", k = " + k);
        //x = 7, y = 6, k = 12
        int z = x++ + ++x - --y + 1;
        //z = 7(x=8) + (x=9)9 - (y=5)5 + 1 = 12
        System.out.println("x = " + x + ", y = " + y + ", z = " + z);
    }
}


#Main.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.gokisoft.c2109i;

import java.util.Scanner;


/**
 *
 * @author Diep.Tran
 */
public class Main {
    public static void main(String[] args) {
        System.out.println("Hello World!!!");
        System.out.println("OKOK");
        
        int x = 10;
        float k = 12.6f;
        char c = 'A';
        boolean isCheck = true;
        
        System.out.println("x = " + x);
        
        String str = "Sinh Vien Aptech 285 Doi Can";
        System.out.println("str = " + str);
        
        System.out.println("str = " + str + ", x = " + x);
        
        System.out.format("\nstr = %s, x = %d, k = %f\n", str, x, k);
        
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Nhap x = ");
//        x = scan.nextInt();
        x = Integer.parseInt(scan.nextLine());
        
        System.out.println("x = " + x);
        
        System.out.println("Nhap k = ");
//        k = scan.nextFloat();
        k = Float.parseFloat(scan.nextLine());
        System.out.println("k = " + k);
        
//        scan.nextLine();
        System.out.println("Nhap str = ");
        str = scan.nextLine();
        System.out.println(str);
        
    }
}


#pom.xml


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.gokisoft.c2109i</groupId>
    <artifactId>C2109I</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>com.gokisoft.c2109i.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>


Tags:



Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó