java基本数据类型

java基本数据结构

基本简介

基本数据类型和三大语句(循环,条件,顺序)这个东西算是所有计算机语言共有的东西,而java又是面对对象语言,所以这些基本数据类型都是类封装出来,可以new出对象的.

首先选择合适的IDE做开发

市面上很多IDE的 Apache基金会的NetBeans,jetbrains的IDEA
还有eclipse基金会的eclipse 还有myeclipse什么的 这些我都用过 说一下个人感受

- Eclipse我用的第一个集成环境,集成很强,提示有点鸡肋,用起来挺僵硬的

  • IDEA这个是真香,用了都说好,让你体会到IDE的智能,而且AS(AndroidStudio)也是这公司开发的,还好pychram等(强烈推荐,群内有免费激活码)
  • 新人推荐吧,由于你们没有学web,所以再练习的时候想要看见程序的运行,java自带的桌面端(GUI),但是这个代码量确实确实了,前端嘛一般都可以画(如微软的VS) ,所以NetBeans可以给新手门提供很好的代码可视化,以后我会大量借助这个
    但是新手之后的web,大家还是要熟悉IDEA

### 基本数据类型
类型(包装类型)型别字节取值范围
byte(Byte)整型1byte-27 ~ 27-1
short (Short)整型2byte-215 ~ 215-1
int (Integer)整型4byte-231 ~ 231-1
long (Long)整型8byte-263 ~ 263-1
float (Float)浮点型4byte3.402823e+38 ~ 1.401298e-45
double (Double)浮点型8byte1.797693e+308~ 4.9000000e-324
char(Character)文本型2byte0~ 216-1
boolean(Boolean)布尔型1bytetrue/false

前六个数据类型 都是数字

  • byte,short,int,long都是整数类型,但是都有各自的取值范围,现在我们的计算机内存够大,所以很少考虑这些占用内存的问题,一般都是用的int,如果存不下就是long

  • 只有在物联网 或者内存很小的开发时 才注重这四个整形的使用

  • float,double都是浮点型,即可以存小数。

  • char 字符类型为什么取值时数字,那请自行百度 ASCII

  • boolean true/false是和否 这个最好理解

Netbeans基本配置和简单使用大家可以自行百度,或者可加下面群获取在这里插入图片描述

接下来写个小例子

/*
 * 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.mycompany.mavenproject2;

/**
 *
 * @author Excalibur
 */
public class Number extends javax.swing.JFrame {


    /**
     * Creates new form Number
     */
    public Number() {

        initComponents();
        lblAddition.setText("");
        lblSubstraction.setText("");
        lblMultiplication.setText("");
        lblDivision.setText("");
        lblExponential.setText("");


    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton2 = new javax.swing.JButton();
        tilte = new javax.swing.JLabel();
        lblMultiplication = new javax.swing.JLabel();
        lblSubstraction = new javax.swing.JLabel();
        lblAddition = new javax.swing.JLabel();
        lblExponential = new javax.swing.JLabel();
        lblDivision = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jButton2.setText("执行");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        tilte.setText("无交互简单计算器");

        lblMultiplication.setText("jLabel3");

        lblSubstraction.setText("jLabel4");

        lblAddition.setText("jLabel5");

        lblExponential.setText("jLabel6");

        lblDivision.setText("jLabel7");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(127, 127, 127))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(147, 147, 147)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblMultiplication)
                            .addComponent(lblSubstraction)
                            .addComponent(lblAddition)
                            .addComponent(lblExponential)
                            .addComponent(lblDivision)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(113, 113, 113)
                        .addComponent(tilte)))
                .addContainerGap(119, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(tilte)
                .addGap(18, 18, 18)
                .addComponent(lblAddition)
                .addGap(18, 18, 18)
                .addComponent(lblSubstraction)
                .addGap(18, 18, 18)
                .addComponent(lblMultiplication)
                .addGap(18, 18, 18)
                .addComponent(lblDivision)
                .addGap(18, 18, 18)
                .addComponent(lblExponential)
                .addGap(51, 51, 51)
                .addComponent(jButton2)
                .addContainerGap(91, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

   private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
	        lblAddition.setText(Integer.toString(10+100));
	        lblSubstraction.setText(Integer.toString(100-45));
	        lblMultiplication.setText(Integer.toString(20*30));
	        lblDivision.setText(Integer.toString(300/30));
	        lblExponential.setText(Integer.toString((int)Math.pow(8,3)));
                
    }                                       

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Number.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Number.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Number.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Number.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Number().setVisible(true);
            }
        });
    }

    
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel lblAddition;
    private javax.swing.JLabel lblDivision;
    private javax.swing.JLabel lblExponential;
    private javax.swing.JLabel lblMultiplication;
    private javax.swing.JLabel lblSubstraction;
    private javax.swing.JLabel tilte;
    // End of variables declaration                   
}

下面这段为核心代码,其他都是GUI界面的代码.这端大概意思为:将Integer(即int的包装类)数据类型转化为字符串然后显示.
执行前:
在这里插入图片描述
点击执行后
在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值