美文网首页
Java随手记

Java随手记

作者: 浅巷墨漓丶 | 来源:发表于2015-12-22 16:43 被阅读0次

(一)JAVA的初级入门随手记 —12月22日

  • 入门程序,输出一个Hello_World;
  • CMD+B运行
// class是创建的一个类,保存的文件名字一定要和Class后的名字一样,大小写都要一致
public class Zhang {
    // main主要的,程序的入口
    public static void main(String[] args) {
        // system语句是输出语句,每条语句后以分号结尾
        // println 是表示输出换行
        System.out.println("Hello_World");
    }
}

(二)JAVA的基本数据类型以及转换 —12月23日

  • 基本数据类型 运算符:+ 加法,— 减法,* 乘法,/ 除法,%是取余
  • 整形:byte(占用1个字节),short(占用2个字节),int(占用4个字节),long(占用8个字节)
  • 浮点型:float(占用4个字节),double(占用8个字节)
  • 字符型:char(占用1个字节)
  • BOOL型:True,False(占用1或4个字节)
  • final常量
  • 类型转换
public class JavaText {
    public static void main(String[] args) {
        // 隐式转换:空间占用小的类型转换为空间占用大的类型,精度不丢失。如
        short s =97;
        int i= sh;
        System.out.println("隐式转换"+i);
        // 强制转换
        long l=1111; 
        int jj=(int)ll;
        System.out.println("强制转换"+jj);
    }
}
  • 字符串的使用
  • String 是字符串的一种类
  • ( )是一种方法,方法的后面都会写上( )
public class JavaText {
    public static void main(String[] args) {
        // 创建字符串
        String str1 = "JAVA练习测试";

        // 字符串长度的方法,返回的是int型
        int le = str1.length();
        System.out.println("字符串的长度为:"+le);
        String str2 = "Java练习测试";

        // 字符串比较的方法,返回的是int型
        int result = str1.compareTo(str2);
        System.out.println("字符串1比字符串2大 "+result+" 位");
        // 用if语句进行判断
        if (str1.compareTo(str2) == 0) {
            System.out.println("字符串1等于字符串2");
        }
        if (str1.compareTo(str2) > 0) {
            System.out.println("字符串1大于字符串2");
        }
        if (str1.compareTo(str2) < 0) {
            System.out.println("字符串1小于字符串2");
        }

        // 字符串不分大小写的比较
        if (str1.compareToIgnoreCase(str2) == 0) {
            System.out.println("字符串1等于字符串2");
        }
        if (str1.compareToIgnoreCase(str2) > 0) {
            System.out.println("字符串1大于字符串2");
        }
        if (str1.compareToIgnoreCase(str2) < 0) {
            System.out.println("字符串1小于字符串2");
        }

        // 字符串比较,返回BOOL型
        if (str1.equals(str2)) {
            System.out.println("str1 等于 str2");
        }else{
            System.out.println("str1 不等于 str2");
        }

        // 查找字符串中的字符,返回int型
        int index1 = str1.indexOf("J");
        System.out.println("J字符在字符串总第" + index1 +"位");
        // 从第X位开始查找字符串中的字符,如果该字符串中没有要查找的字符则返回的是-1
        int index2 = str1.indexOf("S",4);
        System.out.println("S字符在字符串总第" + index2 +"位");

        // 前缀,
        boolean bool1= str1.startsWith("J");
        System.out.println("该字符串是否是以J字符开头:" + bool1);

        boolean bool2 = str2.startsWith("S");
        System.out.println("该字符串是否是以S字符结尾:" + bool2);
    }
}

相关文章

  • 随拍,手记。

  • Spring Security入门

    前言 公众号 《java编程手记》记录JAVA学习日常,分享学习路上点点滴滴,从入门到放弃,欢迎关注 Spring...

  • Spring Security基于DB的权限认证

    前言 公众号 《java编程手记》记录JAVA学习日常,分享学习路上点点滴滴,从入门到放弃,欢迎关注 前面我们已经...

  • Java反射(手记)

    1. 概念 定义:反射主要是指程序可以访问、检测和修改它本身状态或行为的一种能力。在计算机科学领域,反射是一类应用...

  • Java随手记

    (一)JAVA的初级入门随手记 —12月22日 入门程序,输出一个Hello_World; CMD+B运...

  • Java手记——static

    1、static变量 静态变量在内存中只有一个拷贝(节省内存) 在加载类的过程中完成静态变量的内存分配,可用类名直...

  • 2018-09-04

    今天开始随手记录自己学习/复习java的过程。 1。Debug:这个必不可少,肯定是要会的。 2.Java常用的快...

  • 随拍随想随手记

    花都是香的吗?或许这株花就得了狐臭。 物竞天择竞的也只是异类,而人却是会兄弟阋墙,手足相残的。 孔雀园...

  • 随笔

    我影随我形, 我手记我心。 天地入穹庐, 谁人随我心。 哈哈哈哈哈…… 长空踏马去, 一路歌相随。

  • 非常实用的 Java 8 代码片段

    本文来自于我的慕课网手记:非常实用的 Java 8 代码片段,转载请保留链接 ;) 目录 Array (数组相关)...

网友评论

      本文标题:Java随手记

      本文链接:https://www.haomeiwen.com/subject/rqtyhttx.html