移动打车项目1
// 只能用一个类名 和文件名一致
// 模块export andri
//定义一个类 在外界调用
public class HelloJava
{ // 主方法
public static void main(String args[])
{
System.out.printIn("Hello java")
}
// 模块export andri
//定义一个类 在外界调用
public class HelloJava
{ // 主方法
public static void main(String args[])
{
System.out.printIn("Hello java")
}
}
return shell 开启一个线程 执行a.out return 的返回值 返回给shell
calss Dog
{
Dog(){
this.color = "black"
}
Dog(String color){
{
Dog(){
this.color = "black"
}
Dog(String color){
this.color = color
}
public void sleep(){
System.out.println(this.color + "Dog is sleep");
}
private String color;
}
}
public void sleep(){
System.out.println(this.color + "Dog is sleep");
}
private String color;
}
public class Text2_demo
{
public static void main(String args[]){
Dog dog1 = new Dog();
Dog dog2 = new Dog("dahuang");
dog1.sleep();
}
Dog dog2 = new Dog("dahuang");
dog1.sleep();
}
}
值传递 c/c++ 值传递 开辟新空间
java python 基本类型传递的都是值传递, 复杂类型 引用
byte,long double ,boolean, char , 解释方式不同
应用类型: new 出来的都是引用
应用类型: new 出来的都是引用
class test3{
// 共用的 静态 常量 类型
public static final String content = "AC"
// 共用的 静态 常量 类型
public static final String content = "AC"
}
public class Text3
{
public static void main(String args[]){
System.out.println(test3.content);
test3 t = new test3();
System.out.println(t.content);
t.content = "123";
System.out.println(t.content);
}
{
public static void main(String args[]){
System.out.println(test3.content);
test3 t = new test3();
System.out.println(t.content);
t.content = "123";
System.out.println(t.content);
}
}
public class Test4_static{
private int a = 0;
public static void main(String args[]){
private int a = 0;
public static void main(String args[]){
}
}
}
c/c++ : 类中的声明变量
java: 中可以声明定义
静态方法没有this指针;
default: 在当前文件可用
final 常量
对有符号的不能左移。
instanof
公共类
final 常量
对有符号的不能左移。
instanof
公共类
class Hero{
public void attack(){
System.out.println("attack");
}
}
继承
class Yase extends Hero{
// 方法重写
public void attack(){
System.out.println("")
class Yase extends Hero{
// 方法重写
public void attack(){
System.out.println("")
}
}
public class Test_externts()
{
public static doAttack(Hero hero){
if (hero instanceof Yase){
System.out.println("yes");
}
public class Test_externts()
{
public static doAttack(Hero hero){
if (hero instanceof Yase){
System.out.println("yes");
}esle if(hero instanceof Libai)
{
System.out.println("LIBAI");
}
hero.attack();// 多态
{
System.out.println("LIBAI");
}
hero.attack();// 多态
}
public static void main(String args[]){
Hero hero = new Hero();
Hero hero = new Hero();
hero.attack();
Hero y = new Yase();
y.attack();
Hero l = new LiBai();
l.attack();
y.attack();
Hero l = new LiBai();
l.attack();
}
}
静态方法: 类方法
public class Test_Array{
public static void printArray(int[] array){
for(int item: array){
System.out.println(item);
}
for(int item: array){
System.out.println(item);
}
}
// 二维数组
public static void printArray2(int..arry)
{
for(int i; i< array.length;i++)
{
System.out.println(array[i])
}
// 二维数组
public static void printArray2(int..arry)
{
for(int i; i< array.length;i++)
{
System.out.println(array[i])
}
}
public static void main(String args[]){
int[] array1 = {1,2,3,4,5};// 定义一个数组
int[] array2 = new int[5]; // 引用
}
}
数组名值常指针
}
数组名值常指针
组合方式:
class Son1
{
Son1(Fathor fa)
{
this->fa = fa;
}
private:
Fathor *fa;
}
继承方式:
class Son: public Fathor
{
}
导入包
import java.util.Date;
public class Test_date{
public static void main(String args){
Date date = new Date();
System.out.println(date.toString());
}
import java.util.Date;
public class Test_date{
public static void main(String args){
Date date = new Date();
System.out.println(date.toString());
}
}
时间: 系统时间
localtime: 本地时间
格式化时间:
localtime: 本地时间
格式化时间:
import java.util.*
public class Test7{
public static void main(String args[]){
try{
System.out.println(new Date()+"\n");
Thread.sleep(1000*3);
System.out.println(new Date()+"\n");
}catch(Exception e){
System.out.println("Gat an exception");
}
}
}
-----------------------------------------------
// 默认继承 object
class Hero{
Hero(String name){
this.name = name;
}
// 不能修改权限
protected void finalize(){
System.out.println("Gat an exception");
}
}
}
-----------------------------------------------
// 默认继承 object
class Hero{
Hero(String name){
this.name = name;
}
// 不能修改权限
protected void finalize(){
}
private String name;
}
// 不定时回收
public class Test7{
private String name;
}
// 不定时回收
public class Test7{
public static void main(String args[]){
Hero h = new Hero("Gailun");
// 显示调用回收
h = null;
//手动执行
System.gc();
Hero h = new Hero("Gailun");
// 显示调用回收
h = null;
//手动执行
System.gc();
}
}
}
-------------------------------
public class Test7{
public static void main(String args[]){
char[] strArray = {"A","B","C"};
String str1 = new String(strArray);
String str2 = new String("abc");
String str3 = "xye";
String str4;
str4 = String.format("%f,%d,%s",3.14,100,"itcast")
System.out.println(str4);
char[] strArray = {"A","B","C"};
String str1 = new String(strArray);
String str2 = new String("abc");
String str3 = "xye";
String str4;
str4 = String.format("%f,%d,%s",3.14,100,"itcast")
System.out.println(str4);
}
}
}
----------------------------
import java.io.*
import java.io.*
public class Test{
public static void main(String[] args){
byte[] binary = {1,2,3,4,5};
// 输出流 文件流 进程往外流
try{
OutputStream os =new FileOutputStream("test.txt");
public static void main(String[] args){
byte[] binary = {1,2,3,4,5};
// 输出流 文件流 进程往外流
try{
OutputStream os =new FileOutputStream("test.txt");
for(int i=0;i<binary.length; i++){
os.write(binary[i]);
}
os.close();
os.write(binary[i]);
}
os.close();
InputStream is = new FileInputStream("test.txt");
int size = is.available();
for(int i=0;i< size;i++){
System.out.print(is.read()+",");
}
is.close();
}catch(IOException e){
System.out.println("io error");
}
}
}
}
}
}
hexdump: 查看二进制文件表示方式
00000000(地址) 0201 0403 0005
00000005 (地址)
-------------------------------------
抽象类
00000000(地址) 0201 0403 0005
00000005 (地址)
-------------------------------------
抽象类
class Animal{
public void move(){
System.out.print("")
}
}
class Dog extends Animal{
public void move(){
super()
super.move(); // 第一个父类
System.out.print()
}
}
主方法
public class TestDog{
public static void main(String[] args){
public void move(){
System.out.print("")
}
}
class Dog extends Animal{
public void move(){
super()
super.move(); // 第一个父类
System.out.print()
}
}
主方法
public class TestDog{
public static void main(String[] args){
}
}
}
有虚函数
abstract class Animal{
abstract void eat();
String name; //属性
}
class Dog extends Animal{
Dog(String name){
this.name = name;
}
System.out.print(this.name + "sleep");
Dog(String name){
this.name = name;
}
System.out.print(this.name + "sleep");
}
class Test{
public static void show(Animal animal){
animal.eat();
if(animal instanceof Dog){
Dog d = (Dog)animal;
d.eat();
}else if(animal instanceof Cat){
Cat c = (Cat)animal;
c.eat();
}
}
public static void main(String []args){
Animal cat = new Cat("Tom");
Animal dog = new Dog("Big");
show(cat);
show(dog);
}
}
---------------------------
interface Fight{
public void attack();
public void skill();
public void attack();
public void skill();
}
interface Action{
public void run();
public void die();
}
public void run();
public void die();
}
abstract Hero{
Hero(Sting name){
this.name = name;
}
public abstrack void kill();
private String name;
}
Hero(Sting name){
this.name = name;
}
public abstrack void kill();
private String name;
}
class Gailun extends Hero implement Fight,Action{
Gailun(){
super("gailun");
}
// 实现接口
public void attack(){}
public void skill(){}
public void run(){}
public void die(){}
// 实现抽象方法
public void kill(){
Gailun(){
super("gailun");
}
// 实现接口
public void attack(){}
public void skill(){}
public void run(){}
public void die(){}
// 实现抽象方法
public void kill(){
this.run();
this.attack();
this.skill();
this.attack();
this.skill();
}
}
---------------------
mkdir Animals
Animal.java
package animals; //当前模块
接口
public interface Animal{
public void eat();
public void sleep();
}
--------------------
vsp Cat.java
mkdir Animals
Animal.java
package animals; //当前模块
接口
public interface Animal{
public void eat();
public void sleep();
}
--------------------
vsp Cat.java
package animals;
public class Cat implements Animal{
public void eat()
{
System.out.print("hhh");
}
}
public class Cat implements Animal{
public void eat()
{
System.out.print("hhh");
}
}
wq:
一个包: 一个抽象类,两个实体类
-----------------------
import animals.Animal;
import animals.cat
import animals.Dog
import animals.Animal;
import animals.cat
import animals.Dog
public class Test{
public static void main(String args[]){
Animal dog = new Dog();
Animal Cat = new Cat();
}
}
public static void main(String args[]){
Animal dog = new Dog();
Animal Cat = new Cat();
}
}