ORACLE官网JAVA学习文档
Trails Covering the Basics
Figure 1 an overview of the software development process
Figure 3 java平台的两个组件
java MyApp arg1 arg2
class Bicycle{
int cadence=0;
int speed=0;
int gear=1;
void changeCadence(int newValue)
{
cadence=newValue;
}
void changeGear(int newValue)
{
gear=newValue;
}
void speedUp(int increment)
{
speed=speed+increment;
}
void applyBrakes(int increment)
{
speed=speed-decrement;
}
void printStates()
{
System.out.println("cadence:" +
cadence + " speed:" +
speed + " gear:" + gear);
}
}
class BicycleDemo{
public static void main(Stirng[] args)
{
Bicycle bicycle1= new Bicycle();
Bicycle bicycle2= new Bicycle();
bicycle1.changeCadence(50);
bicycle1.speedUp(10);
bicycle1.printStates();
bicycle2.changeCadence(60);
bicycle2.changeGear(20);
bicycle2.speedUp(10);
bicycle2.printStates();
}
}
class MountainBike extends Bicycle
{
//new fieds and methods defining
//a mountaion bike would go there
}
interface Bicycle
{
void changeCadence(int newValue);
void changeGear(int newValue);
void speedUp(int increment);
void applyBrakes(int decrement);
}
class ACMBicycle implements Bicycle
{
int cadence=0;
int speed=0;
int gear=1;
void changeCadence(int newValue)
{
cadence=newValue;
}
void changeGear(int newValue)
{
gear=newValue;
}
void speedUp(int increment)
{
speed=speed+increment;
}
void applyBrakes(int decrement)
{
speed=speed-decrement;
}
void printSatas()
{
System.out.println("cadence"+cadence+"speed"+speed+"gear"+gear)
}
}
byte
|
8-bit
|
Data type
|
Default value(for fields)
|
byte
|
0
|
short
|
0
|
int
|
0
|
long
|
0L
|
float
|
0.0f
|
double
|
0.0d
|
char
|
'\u0000'
|
String(or any object)
|
null
|
boolean
|
false
|
float
|
以F或者f结尾
|
double
|
以D或者d结尾
|
char
|
single quote
|
String
|
double quote
|
byte[] anArrayOfBytes;
short[] anArrayOfShorts;
int[] anArrayOfInts;
long[] anArratOfLongs;
float anArrayOfFloats[]
anArray=new int[10]
int[] anArray=
{
100,20,40,50,
500,12,12,14
}
public static void arrraycopy(Object src, int srcPro
Object dest, int destPos, int length
)
public class Array {
public static void main(String[] argv)
{
char[] copyFrom={'d','e','f','a','b','c','d'};
char[] copyTo=new char[4];
System.arraycopy(copyFrom,3,copyTo,0,4);
System.out.println(new String(copyTo));
}
}
class ArrayCopyDemo
{
public static void main(String[] args)
{
char[] copyForm={'a','b','c','d','e'}
char[] copyTo= java.util.Arrays.copyOfArrays(copyForm,1,4);
System.out.println(new String(copyTo));
}
}
- Searching an array for a specific value to get the index at which it is placed (the
binarySearch
- method).
- Comparing two arrays to determine if they are equal or not (the
equals
- method).
- Filling an array to place a specific value at each index (the
fill
- method).
- Sorting an array into ascending order. This can be done either sequentially, using the
sort
- method, or concurrently, using the
parallelSort
- method introduced in Java SE 8. Parallel sorting of large arrays on multiprocessor systems is faster than sequential array sorting.
Operator
|
Description
|
+
|
Additive
|
-
|
Subtraction operator
|
*
|
Multiplication operator
|
/
|
Division operator
|
%
|
Remainder operator
|
Operator
|
Description
|
+
|
Unary plus operator
|
-
|
Unary minus operator
|
++
|
Increment operator
|
--
|
Decrement operator
|
!
|
Logical complement operator
|
==
|
equal to
|
!=
|
not equal to
|
>
|
gearter than
|
>=
|
greater than or equal to
|
<
|
less than
|
<=
|
less than or equal to
|
public class Array {
public static void main(String[] argv)
{
int value1=1;
int value2=2;
if(value1==value2)
{
System.out.println("value1==value2");
}
if(value1!=value2)
{
System.out.println("value1!=value2")
}
if(value1>value2)
{
System.out.println("value1>vluae2");
}
if(value1<value2)
{
System.out.println("value1<value2");
}
}
}
public class ConditionalDemo1 {
public static void main(String[] argv)
{
int value1 = 1;
int value2 = 2;
if((value1==1)&&(value2==2))
{
System.out.println("value1 is 1 AND value2 is 2");
}
if((value1==1)||(value2==2))
{
System.out.println("value1 is 1 OR value2 is 1");
}
}
}
class ConditionalDemo2 {
public static void main(String[] args){
int value1 = 1;
int value2 = 2;
int result;
boolean someCondition = true;
result = someCondition ? value1 : value2;
System.out.println(result);
}
}
public class InstanceofDemo {
public static void main(String[] args)
{
Parent parent1 = new Parent();
Child child = new Child();
System.out.println("parent1 instanceof Parent "+(parent1 instanceof Parent));
System.out.println("parent1 instanceof Child "+(child instanceof Child));
System.out.println("parent1 instanceof MyInterface "+(parent1 instanceof MyInterface));
System.out.println("child instanceof Parent "+(child instanceof Parent));
System.out.println("child instanceof Child "+(child instanceof Child));
System.out.println("child instanceof MyInterface "+(child instanceof MyInterface));
}
}
class Parent{}
class Child extends Parent implements MyInterface{}
interface MyInterface{}
bitwise &
|
bitwise AND operation
|
bitwise ^
|
exclusive OR operation 位互斥或操作符
|
bitwise |
|
inclusive OR operation 位包换或操作符
|
class BitDemo {
public static void main(String[] args) {
int bitmask = 0x000F;
int val = 0x2222;
// prints "2"
System.out.println(val & bitmask);
}
}
=
|
Simple assignment operator
|
+
|
Additive operator(also used for String concatenation)
|
-
|
Subtraction operator
|
*
|
Multiplication operator
|
/
|
Division operator
|
%
|
Remainder operator
|
+
|
Unary plus operator;indicates positive value
|
-
|
Unary minus operator;negates an exprssion
|
++
|
Increment operator
|
==
|
Equal to
|
!=
|
Not equal to
|
>
|
Greater than
|
>=
|
Greater than or equal to
|
<
|
Less than
|
<=
|
Less than or equal to
|
&&
|
Conditional-And
|
||
|
Conditional-OR
|
?:
|
Ternary
|
instanceof
|
Compares an object to a specified type
|
~
|
Unary bitwise complement
|
<<
|
Signed left shift
|
>>
|
Signed right shift
|
>>>
|
Unsigned right shift
|
&
|
Bitwise AND
|
^
|
Bitwise exclusive OR
|
|
|
Bitwise incluseive OR
|
class IfElseDemo {
public static void main(String[] args) {
int testscore = 76;
char grade;
if (testscore >= 90) {
grade = 'A';
} else if (testscore >= 80) {
grade = 'B';
} else if (testscore >= 70) {
grade = 'C';
} else if (testscore >= 60) {
grade = 'D';
} else {
grade = 'F';
}
System.out.println("Grade = " + grade);
}
}
public class SwithDemoFallThrough
{
public static void main(String[] args)
{
java.util.ArrayList<String> futureMonths = new java.util.ArrayList<String>();
int month = 8;
switch(month)
{
case 1: futureMonths.add("January");
case 2: futureMonths.add("February");
case 3: futureMonths.add("March");
case 4: futureMonths.add("April");
case 5: futureMonths.add("May");
case 6: futureMonths.add("June");
case 7: futureMonths.add("July");
case 8: futureMonths.add("August");
case 9: futureMonths.add("September");
case 10: futureMonths.add("October");
case 11: futureMonths.add("November");
case 12: futureMonths.add("December");
break;
default: break;
}
if(futureMonths.isEmpty())
{
System.out.println("Invalid month number");
}
else
{
for(String monthName:futureMonths)
{
System.out.println(monthName);
}
}
}
}
while(expression)
{
statements
}
do
{
statement(s)
}while(expression)
for(initilization;termination;increment)
{
statement(s)
}
public class EnhancedForDemo {
public static void main(String[] args) {
int[] numbers={1,2,3,4,5,6,7,8};
for(int item: numbers)
{
System.out.println(item);
}
}
}
public class BreakWithLabelDemo {
public static void main(String[] args) {
int[][] arrayOfInts=
{
{32, 87, 3, 589 },
{1, 1076, 2000, 8},
{622, 127, 77, 955}
};
int searchfor =12;
int i;
int j=0;
boolean foundIt= false;
search:for(i=0;i<arrayOfInts.length;i++)
{
for(j=0;j<arrayOfInts[i].length;j++)
{
if(arrayOfInts[i][j]==searchfor)
{
foundIt=true;
break search;
}
}
}
if(foundIt==true)
{
System.out.println("found it!");
}
else
{
System.out.println("not found it!");
}
}
}
public class ContinueWithLabelDemo
{
public static void main(String[] args)
{
String searchMe = "Look for a substring in me";
String substring = "sub";
boolean foundIt = false;
int max=searchMe.length()-substring.length();
test:for(int i=0;i<=max;i++)
{
int n=substring.length();
int j=i;
int k=0;
while(n-- !=0)
{
if(searchMe.charAt(j++)!=substring.charAt(k++))
{
continue test;
}
}
if(foundIt=true)
{
break test;
}
}
if(foundIt)
{
System.out.println("found it");
}
else
{
System.out.println("Not found it");
}
}
}
class MyClass
{
//fields,constructor, and
//method declarations
}
class MyClass extends MySuperClass implements YourInterface
{
//field, constructor, and
//method declarations
}
- 类中的成员变量-叫做字段
- 方法或者代码中的变量叫本地变量
- 字段声明叫做参数
public int cadence
public int gear
public int speed
public class PrivateBicycle
{
private int cadence;
private int gear;
private int speed;
public PrivateBicycle(int startCadence, int startSpeed, int startGear)
{
gear = startGear;
speed = startSpeed;
cadence = startCadence;
}
public int getCadence()
{
return cadence;
}
public int getGear()
{
return gear;
}
public int getSpeed()
{
return speed;
}
public void setCadence(int newValue)
{
cadence = newValue;
}
public void setGear(int newValue)
{
gear = newValue;
}
public void applyBrake(int decrement)
{
speed-=decrement;
}
public void speedUp(int increment)
{
speed+=increment;
}
}
- 修饰符 public , private
- 返回type
- 方法名
- 参数
- an exception list
- 方法体
public class DataArtist
{
public void draw(String s){}
public void draw(int i){}
public void draw(double f){}
public void draw(float f){}
}
Bicycle yourBike = new Bicycle()
public double computePayment(double loanAmt, double rate, double futureValue, int numPeriods)
{
double interest= rate/100.0;
double partial1= Math.pow((1+interest),-numPeriods);
double denominator = (1-partial1)/interest;
double answer = (-loanAmt/denominator)-((futureValue*partial1)/denominator);
return answer;
}
public Polygon polygonFrom(Point[] corners)
{
//method body goes there
}
public Ploygon ploygonFrom(Point... corners)
{
int numberOfSides = corners.length;
double squareOfSide1,lengthOfSides
squareOfSide1 = (corners[1].x-corners[0].x)*(corners[1].x-corners[0])+(corners[1].y-corners[0].x)*(corners[1].y-corners[0].y)
lengthOfSides=Math.sqrt(squareOfSide1);
}
public PrintStream printf(Stirng format,Object... args)
Point originOne = new Point(20,30);
int height = new Rectangle().height;
Rectangle rectOne = new Rectangle(originOne,100,200)
new Rectangle(100,50).getArea()
- Returning values from methods
- The this key word
- Class vs. instance members
- Access control
- 运行完所有方法
- 抵达return 语句
- 抛出异常
public Number returnANumber{
...
}
public ImaginaryNumber returnANumber() {
...
}
public class Point {
public int x = 0;
public int y = 0;
//constructor
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
public class Rectangle {
private int x, y;
private int width, height;
public Rectangle() {
this(0, 0, 1, 1);
}
public Rectangle(int width, int height) {
this(0, 0, width, height);
}
public Rectangle(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
...
}
public static int getNumberOfBicycles
{
return numberOfBicycles;
}
- 实例方法可以直接访问实例方法和实例变量
- 实例方法可以直接访问类变量和类方法;
- 类方法可以直接访问类方法和类变量;
- 类方法不能直接访问实例变量和实例方法,他们必须使用一个对象引用。也不能使用this关键字。因为没有this所指引的实例。
static final double PI = 3.141592653589793;
public class Bicycle
{
public static void main(String[] args) {
System.out.println(Bicycle.getNumberOfBicycle());
}
private int cadence;
private int gear;
private static int numberOfBicycle=2;
public int getCadence() {
return cadence;
}
public void setCadence(int cadence) {
this.cadence = cadence;
}
public int getGear() {
return gear;
}
public void setGear(int gear) {
this.gear = gear;
}
public static int getNumberOfBicycle() {
return numberOfBicycle;
}
public static void setNumberOfBicycle(int numberOfBicycle) {
Bicycle.numberOfBicycle = numberOfBicycle;
}
}
public class BedAndBreakfast {
public static int capacity=10;
private boolean full=false;
}
static
{
// whatever code is needed for initialization goes here
}
class Whatever
{
public static varType myVar=initializeClassVariable();
private static varType initializeClassVariable()
{
//initialization code goes here
}
}
{
// whatever code is needed for initialization goes here
}
class Whatever
{
private varType myVar=initializeInstanceVariable();
protected final varType initializeInstanceVariable()
{
// initialization code goes here
}
}
public class OuterClass {
...
class NestedClass
{
...
}
}
class OuterClass
{
...
static class StaticNestedClass
{
...
}
class innerClass
{
...
}
}
OuterClass.StaticNestedClass
OuterClass.StaticNestedClass nestedObject = new OuterClass.StaticNestedClass
class OuterClass
{
...
class InnerClass
{
...
}
}
OuterClass.InnerClass innerObject= outerObject.new InnerClass();
public class ShowTest
{
public int x=0;
class FirstLevel
{
public int x=1;
void methodInFirstLevel
{
System.out.println(x);
System.out.println(this.x);
System.out.println(ShowTest.this.x);
}
}
public static void main(String args)
{
ShadowTest st = new ShadowTest();
ShadowTest.FirstLevel fl = st.new FirstLevel();
fl.methodInFirstLevel(23);
}
}
x = 23
this.x = 1
ShadowTest.this.x = 0
public class DataStructure {
//create an array
private final static int SIZE =15;
private int[] arrayOFInts = new int[SIZE];
public void printEven()
{
DataStructureIterator iterator = this.new EvenIterator();
while(iterator.hasNext())
{
System.out.println(iterator.next()+" ");
}
System.out.println();
}
interface DataStructureIterator extends java.util.Iterator<Integer>{}
private class EvenIterator implements DataStructureIterator
{
private int nextIndex =0;
public boolean hasNext()
{
return (nextIndex<=SIZE-1);
}
public Integer next()
{
Integer retValue=Integer.valueOf(arrayOFInts[nextIndex]);
nextIndex+=2;
return retValue;
}
}
public static void main(String[] args) {
DataStructure ds = new DataStructure();
ds.printEven();
}
}
ORACLE官网JAVA学习文档的更多相关文章
- dubbo官网和帮助文档
dubbo官网和帮助文档 https://github.com/apache/incubator-dubbo 内含帮助文档: http://dubbo.apache.org/books/dubbo-d ...
- Nmap官网中众多文档如何查看
打开Nmap(nmap.org)官网后,会看多个关于文档的链接,熟悉之后会发现有三类,Reference Guide,Books,Docs.通过熟悉知道Doc是文档的入口,且下面是对Doc页面的翻译, ...
- Oracle官网下载参考文档
最近有人问我有没有Oracle11g数据库官方参考文档,我就想,这不是在官网可以下载到的吗,疑惑,问了之后才知道,他官网找过,但时没有找到.不要笑,其实有很多人一样是找不到的,下面就一步一步操作下: ...
- 解决linux 无法下载 oracle 官网 java的 安装包
wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-co ...
- 官网Android离线文档下载
这是Android的离线API及一些Guide——俗称的/docs文件夹下的内容——英文版的...——http://pan.baidu.com/s/1qXmLlQc
- 如何从sun公司官网下载java API文档(转载)
相信很多同人和我一样,想去官网下载一份纯英文的java API文档,可使sun公司的网站让我实在很头疼,很乱,全是英文!所以就在网上下载了别人提供的下载!可是还是不甘心!其实多去看看这些英文的技术网站 ...
- 从Oracle官网学习oracle数据库和java
网上搜索Oracle官网:oracle官网 进入Oracle官网 点击menu-Documentation-Java/Database,进入Oracle官网的文档网站 首先是Java,可以看到Java ...
- 如何在Oracle官网下载java的JDK最新版本和历史版本
官网上最显眼位置只显示了Java SE的JDK的最新版本下载链接,因为都是英文,如果英文不是很好,寻找之前的JDK版本需要很长时间,而且未必能在那个隐蔽的位置找到之前版本列表. 今天小编来给你详细讲解 ...
- soapUI学习文档(转载)
soapUI 学习文档不是前言的前言记得一个搞开发的同事突然跑来叫能不能做个WebService 性能测试,当时我就凌乱了,不淡定啊,因为我是做测试的,以前连WebService 是什么不知道,毕竟咱 ...
随机推荐
- JS扫雷小游戏
HTML代码 <title> 扫雷 </title> <!-- ondragstart:防拖拽生成新页面 oncontextmenu:屏蔽右键菜单--> <b ...
- sql server数据库查询链接服务器
服务器对象->链接服务器: 或者 select * from sys.servers: 找到服务器对象名称 select * from [服务器对象名称].[数据库名称].dbo.[表名]:
- 阿里P8架构师浅析——MySQL的高并发优化
一.数据库结构的设计 1.数据行的长度不要超过8020字节,如果超过这个长度的话在物理页中这条数据会占用两行从而造成存储碎片,降低查询效率. 2.能够用数字类型的字段尽量选择数字类型而不用字符串类型的 ...
- 开发规范 小白进阶 python代码规范化
开发规范 软件开发,规范项目的目录结构,代码规范,遵循 PeP8规范等等,让你更加清晰的,合理开发 一功能分类(文件名) settings.py配置文件 配置文件放一些静态参数, 划归固定的路径,文件 ...
- .netcore consul实现服务注册与发现-集群部署
一.Consul的集群介绍 Consul Agent有两种运行模式:Server和Client.这里的Server和Client只是Consul集群层面的区分,与搭建在Cluster之上的应用服务无关 ...
- MongoDB实现评论榜
Mongodb很适合做这件事,api的调用仅仅是使用到了入门级别的CRUD,理清楚了思路,编码也会顺风顺水,所以你会发现我在这篇博客中说的比编码还多 评论榜预期的功能 就像是StackOverFlow ...
- 微服务架构 - 网关 Spring Cloud Gateway
Spring Cloud Gateway 工作原理 客户端向 Spring Cloud Gateway 发出请求,如果请求与网关程序定义的路由匹配,则将其发送到网关 Web 处理程序,此处理程序运行特 ...
- shiro登录名的获取
登录名的获取:通过的SecurityUtils的shiro import org.apache.shiro.SecurityUtils; //登录用户名 String loginAccount = S ...
- 渗透之路基础 -- SQL注入
目录 mysql注入(上) limit 有两个参数 limit 2,3 表示从2开始查3条 通过MySql内置数据库获取表名 通过MySql内置数据库获取表名对应的列名 mysql注入(中) SQL常 ...
- Qt无边框窗体-最大化时支持拖拽还原
目录 一.概述 二.效果展示 三.demo制作 1.设计窗体 2.双击放大 四.拖拽 五.相关文章 原文链接:Markdown模板 一.概述 用Qt进行开发界面时,既想要实现友好的用户交互又想界面漂亮 ...