a class is a collection of variables (fields) and functions called methods. A program is a collection of classes. The basic code for declaring a Java class is as follows:

class MyClass{
// This is a single-line comment. /* This is also a comment.
This type of comment can span several lines
*/
}

When declaring a class, the name should always start with a capital letter; this signifies to certain compilers (and human readers of your code) that it is a class (or other similarly-behaved structure that you'll learn about later). If you wish to use a compound phrase (e.g.: "my class") as your class name, you should write it in CamelCase; this means you should capitalize each word and remove spaces between words (e.g.: "MyClass")

Note: Class names cannot begin with numbers or contain any spaces.

Variable

Think of this as a name (identifier) that points to (references) a location in memory where information associated with that name can be stored. In Java (and many other languages), it is a best practice to always start variable names with a lowercase letter and use CamelCase for variable names composed from compound phrases. Variable names cannot contain spaces or special characters (except underscores), though they can contain (but not begin with) numbers. A variable that is a member of a class is called a field.

Each variable has a data type associated with it, which essentially restricts what that variable is allowed to reference. This means your code will not work if you attempt to perform operations on your variables that aren't allowed for that data type.

Note: The = operator is called the assignment operator, so you should interpret = as the English phrase "[left operand] is assigned the value of [right operand]".

A String is a data type that holds a sequence of characters. To create a String variable named that stores the value "Hi!", write the following line of code:

String myString = "Hi!";

The compiler will interpret the characters between the two quotation marks as a String. Saving a reference to our it as variable myString allows us to refer to it again and again by referencing our variable name, myString. 

Note: Some coders use lowercase letters in conjunction with underscores to simulate spaces when declaring variables (e.g.: "my_variable"). This is a style called "lower snake case" and is not the naming convention used in Java, though there are many other languages where you might see this used frequently (e.g.: C, C++, Python, etc.); however, you may see some Java coders begin certain special variable names (e.g.: private class variables or constants) with an underscore to distinguish them from other variables used throughout their program.

Function

A sequence of packaged instructions that perform a task.

Method

In Object-Oriented programming, a method is a type of function that operates on the fields of a class.

int myMethod(){
// ...does cool stuff.
}
void myMethod(int myInt){
// ...does cool stuff.
}

Check out Oracle's Method documentation to learn more.

Object

An Object is an instance (or variable) of a class.

Stream

Think of this as the flow of data from one place to another. Most of our challenges require you to read input from System.in (also known as stdin, the standard input stream), and write output to System.out (also known as stdout, the standard output stream). In Java, the Scanner class is widely used to read input, but each language has its own mechanism for handling IO (input and output).

The syntax for reading from stdin using the Scanner class is as follows:

Scanner scan = new Scanner(System.in);

This creates a new Scanner object that reads from the System.in stream and can be accessed using the variable name scan. To read in information from stdin, you just need to apply Scanner's methods to your scanner object. Here are two basic examples:

scan.next(); // returns the next token of input
scan.hasNext(); // returns true if there is another token of input (false otherwise)
scan.nextLine() // returns the next LINE of input
scan.hasNextLine(); // returns true if there is another line of input

Check out the comprehensive list of Scanner methods to learn more.

When you are finished reading from an input stream, you should close it to avoid a resource leak. The following line of code closes the Scanner object referenced by our scan variable:

scan.close();

Let's say we want to assign a value received from stdin to some String that we'll name , and then print it. We can accomplish this with the following code:

Scanner scan = new Scanner(System.in); // open scanner
String s = scan.next(); // read the next token and save it to 's'
scan.close(); // close scanner
System.out.println(s); // print 's' to System.out, followed by a new line

If the input token is Hi!, the above code will print Hi!.

You can also print text in quotes using System.out.println, or combine quoted text with a variable (e.g.: System.out.println("Input received: " + s);).

30天代码day0的更多相关文章

  1. 30行代码搞定WCF并发性能测试

    [以下只是个人观点,欢迎交流] 30行代码搞定WCF并发性能 轻量级测试. 1. 调用并发测试接口 static void Main()         {               List< ...

  2. 30行代码让你理解angular依赖注入:angular 依赖注入原理

    依赖注入(Dependency Injection,简称DI)是像C#,java等典型的面向对象语言框架设计原则控制反转的一种典型的一种实现方式,angular把它引入到js中,介绍angular依赖 ...

  3. 30行代码实现Javascript中的MVC

    从09年左右开始,MVC逐渐在前端领域大放异彩,并终于在刚刚过去的2015年随着React Native的推出而迎来大爆发:AngularJS.EmberJS.Backbone.ReactJS.Rio ...

  4. Tensorflow快餐教程(1) - 30行代码搞定手写识别

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/lusing/article/details ...

  5. 10分钟教你用python 30行代码搞定简单手写识别!

    欲直接下载代码文件,关注我们的公众号哦!查看历史消息即可! 手写笔记还是电子笔记好呢? 毕业季刚结束,眼瞅着2018级小萌新马上就要来了,老腊肉小编为了咱学弟学妹们的学习,绞尽脑汁准备编一套大学秘籍, ...

  6. JAVA_SE基础——30.构造代码块

    黑马程序员入学blog...构造代码块作用:给所有的对象进行统一的初始化. 问题:要求每个小孩出生都会哭,这份代码有两个构造函数,如果需要每个小孩出生都要哭的话,那么就需要在不同的构造函数中都调用cr ...

  7. 30 行代码实现 JS 中的 MVC

    一连串的名字走马观花式的出现和更迭,它们中一些已经渐渐淡出了大家的视野,一些还在迅速茁壮成长,一些则已经在特定的生态环境中独当一面舍我其谁.但不论如何,MVC已经并将持续深刻地影响前端工程师们的思维方 ...

  8. 30行代码消费腾讯人工智能开放平台提供的自然语言处理API

    腾讯人工智能AI开放平台上提供了很多免费的人工智能API,开发人员只需要一个QQ号就可以登录进去使用. 腾讯人工智能AI开放平台的地址:https://ai.qq.com/ 里面的好东西很多,以自然语 ...

  9. 数据结构 | 30行代码,手把手带你实现Trie树

    本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是算法和数据结构专题的第28篇文章,我们一起来聊聊一个经典的字符串处理数据结构--Trie. 在之前的4篇文章当中我们介绍了关于博弈论的 ...

随机推荐

  1. 【Alpha】事后分析

    Alpha阶段终于告一段落,我们的团队也完整经历了从提出设想.用户需求分析,到开发.测试,再到部署上线.推广的流程."葫芦娃不想写代码"团队还是较出色地完成了Alpha阶段的工作, ...

  2. python学习------模块

    模块(modue)的概念 在计算机程序开发过程中,随着程序代码越写越多,在一个文件里代码就会越来越长,越来越不容易维护. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,这样,每个文件 ...

  3. [Oracle][DATAGUARD] LOGICAL STANDBY环境里,有些SEQUENCE无法应用,导致Primary和Standby无法同期

    今天遇到了一个客户,问题是这样的,客户构筑了一个RACtoRAC的 LOGICAL STANDBY环境.并用EM在监视同期情况,发现EM页面上55115和55116这两个SEQUENCE一直在应用. ...

  4. (简单)华为Nova3 PAR-AL00的USB调试模式在哪里开启的步骤

    当我们使用Pc链接安卓手机的时候,如果手机没有开启Usb调试模式,Pc则没能够成功检测到我们的手机,有时候我们使用的一些功能比较强的的APP如之前我们使用的一个APP引号精灵,老版本就需要开启Usb调 ...

  5. JAVA面向对象之继承

    继承: 子类继承父类的特征和行为,使得子类对象(实例)具有父类的实例域和方法 class 子类 extends 父类 { } 继承的特性: 子类拥有父类非private的属性,方法. 子类可以拥有自己 ...

  6. 实现简单的ssh功能

    客户端代码: # -*- coding=utf-8 -*- __Author__ = "Dennis" import socket client = socket.socket() ...

  7. node.js安装使用express框架

    官网:http://www.expressjs.com.cn/ 使用方式(如果后面需要添加路由等推荐第二种方式,不然需要需要手动添加):一.自己动手搭建 1. 新建项目文件夹,如test,并在命令行中 ...

  8. Springboot 的错误处理功能的实现

    一.页面的形式返回 直接在resources的目录下创建public/error的路径,然后创建5xx.html或者4xx.html文件,如果出错就会自动跳转的相应的页面. 二.cotroller的形 ...

  9. return 返回值

    # ### return 返回值 """ (1) return + 数据类型 : 将这个数据弹到函数的调用处,后面除了可以接六大标准数据类型之外,还可以返回类 对象 函数 ...

  10. web页面空白,无任何显示

    解决前: 解决后: 原因:HTML代码有误,没有关闭script标签. 解决方法:加</script>