4、Java面向对象编程入门与实战

Java面向对象编程入门与实战

1. 类与对象

Java是一种面向对象的语言,它具备表示现实世界中对象的结构。每个Java程序至少包含一个类,这个类知道如何执行特定的操作或表示某种类型的对象。例如,最简单的类 HelloWorld ,它知道如何向世界打招呼。

Java中的类可以有方法(也称为函数)和字段(也称为属性)。以下是一个名为 Car 的类的示例:

class Car{
    String color;
    int numberOfDoors;
    void startEngine() {
       // Some code goes here
    }
    void stopEngine() {
        int tempCounter=0;  
        // Some code goes here
    }
}

Car 类代表了许多不同汽车的共同特征:所有汽车都有颜色和车门数量等属性,并且都能执行类似的操作。我们还可以创建一个更具体的类,例如 JamesBondCar ,它是 Car 的子类,使用Java语法表示为 JamesBondCar extends Car :

class JamesBondCar extends Car{
    int currentSubmergeDepth

相关推荐

20、Java 方法与面向对象编程入门

本文详细介绍了Java中方法的基础知识、面向对象编程(OOP)的核心概念及其在Android开发中的应用。内容涵盖类的定义与实例化、构造方法的作用与自定义、静态成员与实例成员的区别、方法重载的使用等。通过具体的代码示例,帮助读者理解如何在实际项目中运用这些概念,为构建复杂的应用程序奠定基础。

android的专栏 52

4、面向对象编程与Java基础入门

本文详细介绍了面向对象编程与Java基础入门知识,包括过程式编程与面向对象编程的区别、封装和数据隐藏的概念、常见编程问题与解答、Java程序的基本结构以及编程练习等内容。通过学习,读者可以掌握Java编程的核心基础,并为后续深入学习打下坚实基础。

dapp9builder的博客 39

1、Java编程入门:掌握面向对象编程的基础

本博文详细介绍了Java编程的基础知识,包括注释的使用、类的声明与main方法的作用,以及数据类型、运算符和控制结构等内容。此外,还讲解了代码块与作用域的概念,并提供了输入输出的实际示例,为初学者掌握Java编程打下坚实基础。

garlic的博客 328

Java EE 中的面向对象编程思想

Java EE(Java Enterprise Edition)是用于开发企业级应用的 Java 平台,它提供了一系列的 API 和服务,帮助开发者构建大规模、分布式、可扩展的应用程序。面向对象编程(Object-Oriented Programming,OOP)思想是 Java 语言的核心特性之一,在 Java EE 中有着广泛的应用。本文的目的是深入探讨 Java EE 中面向对象编程思想的原理、应用和实践,范围涵盖面向对象编程的核心概念、算法原理、数学模型、项目实战、实际应用场景等方面。

Java大师兄的博客 858

9、Java编程基础与面向对象编程入门

本文详细介绍了Java编程的基础知识和面向对象编程的核心概念。内容涵盖变量声明、赋值操作、数据类型、运算符使用、代码调试技巧以及Java类与对象的基本结构。同时,还介绍了构造函数的使用、方法调用、对象引用、Java预定义类库如String、Math、Random和Scanner等的实用示例。通过丰富的代码示例和编程项目,帮助初学者掌握Java编程的核心技能。

neovim7hacker的博客 36

39、Java 面向对象编程入门

本博客详细介绍了 Java 面向对象编程(OOP)的基础知识,包括对象、类、状态与行为、构造函数以及封装等核心概念。通过示例代码和实际案例(如 Point 类和 Stock 类),帮助读者理解如何在 Java 中创建和使用对象,并展示了面向对象设计的优势。内容适合初学者入门 OOP 编程思想,并为进一步学习 Java 打下坚实基础。

o9p0q1的博客 95

13、Java 编程基础与面向对象编程入门

本博客详细介绍了Java编程的基础知识和面向对象编程的概念。内容涵盖变量、运算符、条件语句等基础语法,以及类、对象、方法和实例变量等面向对象编程的核心思想。通过丰富的示例和练习,如整数操作、图形输出、数学计算等,帮助读者逐步掌握Java编程技能,为开发复杂应用程序打下坚实基础。

tgb34567890的博客 43

国产HDMI2.0芯片GSV2011怎么选?手把手教你用它设计音视频采集卡(附FPGA/海思对接指南)

本文详细解析国产HDMI2.0芯片GSV2011在音视频采集卡设计中的应用,涵盖芯片选型、硬件设计要点及与FPGA/海思平台的对接指南。GSV2011凭借4K@60Hz支持、音频提取嵌入功能和高集成度,成为音视频设备的核心选择,助力开发者快速实现高性能采集卡设计。

weixin_30181209的博客 333

【微知】关于GB200 NVL72服务器的一些信息?(36CPU72GPU;LPDDR5X 17T;HBM3e 13.5T;5代NVlink 1.8TB; 720P算力FP8;120Kw)

本文仅根据官网介绍分析,存在纰漏仅供参考。

技术札记 5389

用Python写个彩票小助手:自动生成双色球/大乐透号码并保存到桌面

本文介绍如何使用Python开发一个智能彩票助手,实现双色球和大乐透号码的随机生成与桌面文件保存功能。通过详细的代码示例,包括随机号码生成、文件操作、用户交互和错误处理,帮助Python初学者快速掌握实用工具开发技巧。

weixin_42566121的博客 520

手把手教你用神经网络优化电机控制:从Simulink仿真到实际部署

本文提供了一套完整的工程实践指南,详细讲解了如何将神经网络应用于电机控制,从Simulink仿真建模、轻量级网络设计,到关键的模型量化与代码生成,最终实现向DSP/FPGA硬件的实际部署。文章直面实时性、精度与资源限制等核心工程挑战,为工程师提供了从理论到落地的清晰路径和实用避坑策略。

weixin_29246195的博客 226

自动化专业与嵌入式

在学生时期,我是一个典型的学渣,所以只能选择电气工程、汽修、数控之类的专业。而那些高分的则可以选择计算机,电子商务,通信之类的。这些专业看起来像是蓝领和白领的分界,至今我都觉得这种制度是不人性化的。专业这块根据学生的爱好去选择是最好的,毕竟有兴趣才会”真心”去学习。谁说学渣就学不会编程、学不会金融对吧?不过也罢,在学校能学到东西的毕竟是少数,最近有些大学生发了他们的课程表给我看了下。我感觉学的太广了,什么单片机、c语言、java之类的,导致很多学生学完以后还是很迷茫,不知道自己专业到底是从事什么方向的。所以

m0_71017841的博客 3589

educoder数字逻辑实训:寄存器设计与应用(Logisim)

第1关:基本寄存器的设计 任务描述 本关任务:在Logisim中,构建由4个D触发器构成的4位基本寄存器,要求上升沿触发,具有异步复位功能。 第2关:移位寄存器的设计 任务描述 本关任务:在Logisim中,构建由4个D触发器构成的4位右移移位寄存器,要求上升沿触发,具有异步复位功能。 第3关:循环移位寄存器的设计 任务描述 本关任务:在Logisim中,构建由4个D触发器构成的4位循环右移移位寄存器,要求上升沿触发,具有异步复位功能以及并行数据同步加载功能。 第4关:并行..

qq_52209002的博客 1万+

芒果YOLO11改进23:主干Backbone篇GhostNet:原创改进高效 GhostNet 网络,华为出品,打造全新检测器

主干Backbone篇GhostNet:原创改进高效 GhostNet 网络,华为出品,打造全新检测器

包括YOLOv5、YOLOv7、YOLOv8等模型改进 406

通信算法之334:无人机侦测-DJI 大疆云哨接收机系列

【代码】通信算法之334:DJI 大疆 云哨接收机算法流程。

leegang12的专栏 844

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

上一篇: 18、动态数据集频繁项集挖掘与原型选择方法研究
下一篇: 5、Java编程中的类与方法详解
废话输出机427
博客等级 码龄4年 414粉丝 1552原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值