1, JAVA classification
Divided by language version: JavaSE, JavaME, JavaEE Are classified according to the application: The application, an applet |
2, Installation and Configuration
Environment variable configuration
Adding system variables path jdk path: I: \ 03JAVA \ Java \ jdk-13.0.2 \ bin Increase user variables, variable names classpath, the contents of the bit. "" |
Detecting whether the configuration is successful, DOS window, enter the following command cmd
Javac // detect path configuration Java // detect classpath configuration |
3, the Java program uses process
File 1), write source code, save it as a Java 2) using the javac command to compile the Java file // javac file name .java 3), the compiler generates byte code files (.class) 4), Java instructions, JVM bytecode virtual machine file interpreted // java file name 5), the output |
Java features:
1), cross-platform, as long as the Java runtime system of the machine can perform 2) semi-compiled half explanation, compile the source code into byte code, Java interpreter (operating system) can be directly interpreted Java bytecode |
Batch to be compiled
I: \ 03 JAVA \ EditPlus \ 11> javac * .java // all JAVA file paths are compiled under 11 |
However, if a file has JAVA wrong, all the files can not be compiled |
4, simple code
public class Demo3 { // Public representation of the public, this is a modifier // class definition of class representation public static void main(String[] args) { /* Public representation of the public, this is a modifier Static represents static, it is a modifier Void means no return value The method name main inlet, a main process program executed represents string:表示字符串 []:表示数组 args:表示参数名字,可以是任意合法的名字 */ System.out.println("Hello World!"); // println表示打印换行(ln),可使用print只打印不换行 //需要打印输出的内容,放在英文双引号之内 } } |
public class demo1{ public static void main(String[] args) { System.out.println("Hello World!"); System.out.println("Hello KITTY!"); }} //输出Hello World! Hello KITTY! |
public class demo2{ public static void main(String[] args) { System.out.print("Hello World!"); System.out.print("Hello KITTY!"); }} //输出Hello World!Hello KITTY! |
在定义类的时候,如果是public class定义,那类名就必须和文件名保持一致;而如果只使用class定义,那类名就可以和文件名不一样。
class d5{ public static void main(String[] args) { System.out.print("Hello World!"); System.out.print("Hello KITTY!"); }} javac demo3.java //文件名为demo3,编译 java d5 //类名为d5,执行输出结果为Hello World!Hello KITTY! |
笔试题:public class和class的区别?
1)、在定义类的时候,如果是public class定义,那类名就必须和文件名保持一致;而如果只使用class定义,那类名就可以和文件名不一样 2)、在一个文件中,可以定义多个类,但是public class的类最多只能有1个 |
args:表示参数名字,可以是任意合法的名字,如下例修改args后仍可正常执行
public class demo6{ public static void main(String[] china) { System.out.println("修改了args"); } } |
注意:JAVA严格区分大小写
5、 注释
1)、单行注释
class d5{ public static void main(String[] args) { System.out.print("Hello World!"); //这是注释,无法输出 }} |
2)、多行注释
class d5{ public static void main(String[] args) { /* Public表示公共的,这是一个修饰符 Static表示静态的,这是一个修饰符 Void表示无返回值 main方法名称 */ System.out.print("Hello World!"); }} |
3)、文档注释
生成帮助文档,指令:javadoc 文件名.java
/** */
/** @author chyl */ public class demo5{ //Public表示公共的,这是一个修饰符 //class表示定义类 public static void main(String[] args) { /* Public表示公共的,这是一个修饰符 Static表示静态的,这是一个修饰符 Void表示无返回值 main方法名称,主方法,表示程序执行的入口 string:表示字符串 []:表示数组 args:表示参数名字,可以是任意合法的名字 */ System.out.print("Hello World!"); } } |
javadoc demo5.java //该指令生成了帮助文档,解释此文件 |
6、 类的命名规范
1) 组成由字母、数字、下划线、货币符号组成
2) 不能以数字开头
3) 可以包含汉字韩文日文等,但不建议
4) 长度不能超过255个字符
5) 建议首字母大写,规范写法
6) 采用驼峰法命名,如果类名很长由多个单词组成,则将每个单词的首字母大写
7) JAVA字符集是Unicode码,所以内容和命名必须满足Unicode码的规范
class 类名 { public static void main(String[] args) { System.out.println("类名的命名规范"); } } //类名可以是:A1a、我是类名、A_a、A¥ |
7、 关于主方法的解释
public static void main(String[] args) { } |
主方法肯定是没有返回值的,所以必须使用void
主方法的组成是固定的,也就是每个部分都是不可或缺也不呢个增加的,但是顺序是可以改变的。
修饰符的顺序可以改变,数组[]的位置也可以改变 |
static public void main(String[] args) { } |
public static void main(String args[]) { } |
8、 基本数据类型
类型 |
英文 |
范围 |
所占字节 |
位数 |
字节型 |
Byte |
-128 ~ 127 |
1 |
8 |
短整型 |
Short |
-215 ~ 215-1 |
2 |
16 |
整型 |
Int |
-231 ~ 231-1 |
4 |
32 |
长整型 |
long |
-263 ~ 263-1 |
8 |
64 |
单精度浮点 |
Float |
-3.403E38 ~ 3.403E38 |
4 |
32 |
双精度浮点 |
Double |
-1.798E308 ~ 1.798E308 |
8 |
64 |
字符型 |
Char |
‘\u0000’ ~ ’\uffff’ 或 0 ~ 65536 |
2 |
16 |
布尔型 |
boolean |
True/false |
|
|
Java语言的整型常量默认为int型,声明long型后面需要加上L或l(小写l易与1混淆,建议写大写L); Java浮点型常量默认为double,如要声明一个常量为float,则需要再数字后面加f/F,如:
int a = 15 ; |
double d = 12345.6 ; |
long b = 155555L ; |
float f = 12.3f ; |
作者:kerwin-chyl
文章链接:https:////www.cnblogs.com/kerwin-chyl
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利