Java入门学习-理解int,String,理解类、方法,理解return的用法。

一、自己理解

1、int
整型,像1,2,3这样的数字
2、string
字符串型,一段话(中文英文数字符号都可以)
3、类
世界抽象出来的集合,包括属性和方法
4、方法
事情怎么做
5、return
方法有进有出,return属于出,返回做事情的结果

二、看官方文档后再整理

首先,因为Java是静态语言,所以必须提前定义
1、int
①属于基本类型( primitive data types,8种:byte、short、int、long、float、double、char、boolean)
②占32个二进制位(-2^31 ~ 2^31-1),即占4个字节,Java8之后可以使用它做无符号32位整数(0~2^32-1)- -此处不太明白,怎么做就是无符号了
③默认值为0 //eclipse编辑时,不赋值输出会报错
例:int i = 100000;

2、String
①属于对象,一串字符(a sequence of characters),该类运行创造和操作
例:
②初始化:String s=new String; //输出s为空,什么都不显示
赋值初始化:String greeting = "Hello world!";
③求长度:string.length();
④连接字符串:string1.concat(string2);
⑤格式化字符串:

String fs;
fs = String.format("The value of the float " +
                   "variable is %f, while " +
                   "the value of the " + 
                   "integer variable is %d, " +
                   " and the string is %s",
                   floatVar, intVar, stringVar);
System.out.println(fs);

3.类和方法
①类的实质是一种数据类型,类似于int、char等基本类型,不同的是它是一种复杂的数据类型。因为它的本质是类型,而不是数据,所以不存在于内存中,不能被直接操作,只有被实例化为对象时,才会变得可操作。如下例子,Bicycle为一个类,里面有Bicycle的3个字段(属性),一个构造函数,一个方法
②方法是语句的集合,它们在一起执行一个功能。

public class Bicycle {

    // the Bicycle class has three fields
    public int cadence;
    public int gear;
    public int speed;

    // the Bicycle class has one constructor
    public Bicycle(int startCadence, int startSpeed, int startGear) {
        gear = startGear;
        cadence = startCadence;
        speed = startSpeed;
    }

    // the Bicycle class has one methods
    public void setCadence(int newValue) {
        cadence = newValue;
    }

4、return的用法
①当执行完方法的所有语句后,返回声明类型或者抛出一个异常
②可以返回空、基本类型、引用类型

The class of the type of the returned object must be either a subclass of, or the exact class of, the return type.
我理解为声明为类时,返回只能为类的子类,类的实例,声明的类。
另外,子类方法不能返回父类,因为父类不一定是子类了

三、总结疑问与查找答案

1、怎么做就是无符号了
static String toUnsignedString(int/long i):该方法将指定int或long型整数转换为无符号整数对应的字符串
static String toUnsignedString(int i/long,int radix):转换为指定进制的无符号整数对应的字符串
static xxx parseUnsignedXxx(String s):该方法将指定字符串解析成无符号整数。当调用类为Integer时,xxx代表int;当调用类是Long时,xxx代表long
static xxx parseUnsignedxxx(String s,int radix):将指定字符串按指定进制解析成无符号整数
static int compareUnsigned(int x,int y):该方法将x,y两个整数转换为无符号整数后比较大小。Long方法相同。
static long divideUnsigned(long dividend,long divisor):该方法将x、y两个整数转换为无符号整数后计算他们相除的商。
static long remainderUnsigned(long dividend,long divisor):转换为无符号整数后计算他们相除的余数。

java8还为Byte、Short增加了toUnsignedInt(xxx x) 、toUnsignedLong(yyy x)两个方法,这两个方法用于将指定byte或short类型的变量或值转换成无符号的int或long值

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值