java基础(超赞!!!)

点赞功能设计 点赞功能的设计 每一次点赞,需要记录: (1)谁点的赞; (2)为那篇文章点的赞; (3)点赞时间 (4)是否已经取消点赞   数据表设计 点赞记录表 列名 数据类型 说明 id N 数据表id user_id N 用户id vote_time 阅读详情
我是技术搬运工,好东西当然要和大家分享啦 原文地址

关键字

1. final

数据

声明数据为常量,可以是编译时常量,也可以是在运行时被初始化后不能被改变的常量。

  • 对于基本类型,final 使数值不变;
  • 对于引用类型,final 使引用不变,也就不能引用其它对象,但是被引用的对象本身是可以修改的。

方法

声明方法不能被子类覆盖。

private 方法隐式地被指定为 final,如果在子类中定义的方法和基类中的一个 private 方法签名相同,此时子类的方法不是覆盖基类方法,而是重载了。

类

声明类不允许被继承。

2. static

静态变量

静态变量在内存中只存在一份,只在类第一次实例化时初始化一次。

  • 静态变量: 类所有的实例都共享静态变量,可以直接通过类名来访问它;
  • 实例变量:每创建一个实例就会产生一个实例变量,它与该实例同生共死。

静态方法

静态方法在类加载的时候就存在了,它不依赖于任何实例,所以 static 方法必须实现,也就是说它不能是抽象方法(abstract)。

静态语句块

静态语句块和静态变量一样在类第一次实例化时运行一次。

初始化顺序

静态数据优先于其它数据的初始化,静态变量和静态语句块哪个先运行取决于它们在代码中的顺序。

public static String staticField = "静态变量";
static {
    System.out.println("静态语句块");
}

实例变量和普通语句块的初始化在静态变量和静态语句块初始化结束之后。

public String field = "实例变量";
{
    System.out.println("普通语句块");
}

最后才是构造函数中的数据进行初始化

public InitialOrderTest() {
    System.out.println("构造函数");
}

存在继承的情况下,初始化顺序为:

  1. 父类(静态变量、静态语句块块)
  2. 子类(静态变量、静态语句块)
  3. 父类(实例变量、普通语句块)
  4. 父类(构造函数)
  5. 子类(实例变量、普通语句块)
  6. 子类(构造函数)

Object 通用方法

1. 概览

public final native Class<?> getClass()

public native int hashCode()

public boolean equals(Object obj)

protected native Object clone() throws CloneNotSupportedException

public String toString()

public final native void notify()

public final native void notifyAll()

public final native void wait(long timeout) throws InterruptedException

public final void wait(long timeout, int nanos) throws InterruptedException

public final void wait() throws InterruptedException

protected void finalize() throws Throwable {}

2. clone()

浅拷贝

引用类型引用同一个对象。clone() 方法默认就是浅拷贝实现。


深拷贝

可以使用序列化实现。


How do I copy an object in Java?

3. equals()

== 与 equals() 区别

  • 对于基本类型,== 就是判断两个值是否相等;

  • 对于引用类型,== 是判断两个引用是否引用同一个对象,而 equals() 是判断引用的对象是否等价。

等价性

散列

继承

1. 访问权限

Java 中有三个访问权限修饰符:private、protected 以及 public,如果不加访问修饰符,表示包级可见。

可以对类或类中的成员(字段以及方法)加上访问修饰符。成员可见表示其它类可以用成员所在类的对象访问到该成员;类可见表示其它类可以用这个类创建对象。在理解类的可见性时,可以把类当做包中的一个成员,然后包表示一个类,那么就可以类比成员的可见性。

protected 用于修饰成员,表示在继承体系中成员对于子类可见。但是这个访问修饰符对于类没有意义,因为包没有继承体系。

更详细的内容:浅析 Java 中的访问权限控制

2. 抽象类与接口

抽象类和抽象方法都使用 abstract 进行声明。抽象类一般会包含抽象方法,但是少数情况下可以不包含,例如 HttpServlet 类,但是抽象方法一定位于抽象类中。抽象类和普通类最大的区别是,抽象类不能被实例化,需要继承抽象类才能实例化其子类。

public abstract class GenericServlet implements Servlet, ServletConfig, Serializable {
    // abstract method
    abstract void service(ServletRequest req, ServletResponse res);

    void init() {
        // Its implementation
    }
    // other method related to Servlet
}

接口定义了一组方法,但是接口都没有方法的实现,可以理解为这些方法都是抽象方法。

public interface Externalizable extends Serializable {

    void writeExternal(ObjectOutput out) throws IOException;

    void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
}
参数抽象类接口
默认的方法实现它可以有默认的方法实现接口完全是抽象的。它根本不存在方法的实现
实现子类使用 extends 关键字来继承抽象类。如果子类不是抽象类的话,它需要提供抽象类中所有声明的方法的实现。子类使用关键字 implements 来实现接口。它需要提供接口中所有声明的方法的实现
构造器抽象类可以有构造器接口不能有构造器
与正常 Java 类的区别除了你不能实例化抽象类之外,它和普通 Java 类没有任何区别接口是完全不同的类型
访问修饰符抽象方法可以有 public、protected 和 default 这些修饰符接口方法默认修饰符是 public 。你不可以使用其它修饰符。
main 方法抽象方法可以有 main 方法并且我们可以运行它接口没有 main 方法,因此我们不能运行它。
多继承抽象方法可以继承一个类和实现多个接口接口只可以继承一个或多个其它接口
速度它比接口速度要快接口是稍微有点慢的,因为它需要时间去寻找在类中实现的方法。
添加新方法如果你往抽象类中添加新的方法,你可以给它提供默认的实现。因此你不需要改变你现在的代码。如果你往接口中添加方法,那么你必须改变实现该接口的类。

Java 抽象类与接口的区别

3. super

访问父类的成员

如果子类覆盖了父类的中某个方法的实现,那么就可以通过使用 super 关键字来引用父类的方法实现。

public class Superclass {
    public void printMethod() {
        System.out.println("Printed in Superclass.");
    }
}
public class Subclass extends Superclass {
    // Overrides printMethod in Superclass
    public void printMethod() {
        super.printMethod();
        System.out.println("Printed in Subclass");
    }
    public static void main(String[] args) {
        Subclass s = new Subclass();
        s.printMethod();
    }
}

访问父类的构造函数

可以使用 super() 函数访问父类的构造函数,从而完成一些初始化的工作。

public MountainBike(int startHeight, int startCadence, int startSpeed, int startGear) {
    super(startCadence, startSpeed, startGear);
    seatHeight = startHeight;
}

Using the Keyword super

4. 重载与重写

  • 重写存在于继承体系中,指子类实现了一个与父类在方法声明上完全相同的一个方法;

  • 重载即存在于继承体系中,也存在于同一个类中,指一个方法与已经存在的方法或者父类的方法名称上相同,但是参数类型、个数、顺序至少有一个不同。应该注意的是,返回值不同,其它都相同不算是重载。

String

1. String, StringBuffer and StringBuilder

是否可变

String 不可变,StringBuffer 和 StringBuilder 可变。

是否线程安全

String 不可变,因此是线程安全的。

StringBuilder 不是线程安全的;StringBuffer 是线程安全的,使用 synchronized 来同步。

String, StringBuffer, and StringBuilder

2. String 不可变的原因

可以缓存 hash 值

因为 String 的 hash 值经常被使用,例如 String 用做 HashMap 等。不可变的特性可以使得 hash 值也不可变,因此就只需要进行一次计算。

String Pool 的需要

如果 String 已经被创建过了,那么就会从 String Pool 中取得引用。只有 String 是不可变的,才可能使用 String Pool。


安全性

String 经常作为参数,String 不可变性可以保证参数不可变。例如在作为网络连接参数的情况下如果 String 是可变的,那么在网络连接过程中,String 被改变,改变 String 对象的那一方以为现在连接的是其它主机,而实际情况却不一定是。

线程安全

String 不可变性天生具备线程安全,可以在多个线程中使用。

Why String is immutable in Java?

3. String.intern()

使用 String.intern() 可以保证所有相同内容的字符串变量引用相同的内存对象。

更详细的内容:揭开 String.intern() 那神秘的面纱

基本类型与运算

1. 包装类型

八个基本类型:boolean 1 byte 8 char 16 short 16 int 32 float 32 long 64 double 64

基本类型都有对应的包装类型,它们之间的赋值使用自动装箱与拆箱完成。

Integer x = 2;     // 装箱
int y = x;         // 拆箱

new Integer(123) 与 Integer.valueOf(123) 的区别在于,Integer.valueOf(123) 可能会使用缓存对象,因此多次使用 Integer.valueOf(123) 会取得同一个对象的引用。

public static void main(String[] args) {
     Integer a = new Integer(1);
     Integer b = new Integer(1);
     System.out.println("a==b? " + (a==b));

     Integer c = Integer.valueOf(1);
     Integer d = Integer.valueOf(1);
     System.out.println("c==d? " + (c==d));
 }
a==b? false
c==d? true

valueOf() 方法的实现比较简单,就是先判断值是否在缓存池中,如果在的话就直接使用缓存池的内容。

public static Integer valueOf(int i) {
    final int offset = 128;
    if (i >= -128 && i <= 127) { // must cache
        return IntegerCache.cache[i + offset];
    }
    return new Integer(i);
}

The following is the list of primitives stored as immutable objects:

  • boolean values true and false
  • all byte values
  • short values between -128 and 127
  • int values between -128 and 127
  • char in the range \u0000 to \u007F

自动装箱过程编译器会调用 valueOf() 方法,因此多个 Integer 对象使用装箱来创建并且值相同,那么就会引用相同的对象,这样做很显然是为了节省内存开销。

Integer x = 1;
Integer y = 1;
System.out.println(c==d); // true

Differences between new Integer(123), Integer.valueOf(123) and just 123

2. switch

A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types and a few special classes that "wrap" certain primitive types: Character, Byte, Short, and Integer.

In the JDK 7 release, you can use a String object in the expression of a switch statement.

switch 不支持 long,是因为 swicth 的设计初衷是为那些只需要对少数几个值进行等值判断,如果值过于复杂,那么还是用 if 比较合适。

Why can't your switch statement data type be long, Java?

switch 使用查找表的方式来实现,JVM 中使用的指令是 lookupswitch。

public static void main(String... args) {
  switch (1) {
  case 1:
    break;
  case 2:
    break;
  }
}

public static void main(java.lang.String[]);
  Code:
   Stack=1, Locals=1, Args_size=1
   0:   iconst_1
   1:   lookupswitch{ //2
                1: 28;
                2: 31;
                default: 31 }
   28:  goto    31
   31:  return

How does Java's switch work under the hood?

反射

每个类都有一个 Class 对象,包含了与类有关的信息。当编译一个新类时,会产生一个同名的 .class 文件,该文件内容保存着 Class 对象。

类加载相当于 Class 对象的加载。类在第一次使用时才动态加载到 JVM 中,可以使用 Class.forName('com.mysql.jdbc.Driver.class') 这种方式来控制类的加载,该方法会返回一个 Class 对象。

反射可以提供运行时的类信息,并且这个类可以在运行时才加载进来,甚至在编译时期该类的 .class 不存在也可以加载进来。

Class 和 java.lang.reflect 一起对反射提供了支持,java.lang.reflect 类库包含了 Field 、Method 以及 Constructor 类。可以使用 get() 和 set() 方法读取和修改 Field 对象关联的字段,可以使用 invoke() 方法调用与 Method 对象关联的方法,可以用 Constructor 创建新的对象。

IDE 使用反射机制获取类的信息,在使用一个类的对象时,能够把类的字段、方法和构造函数等信息列出来供用户选择。

更详细的内容:深入解析 Java 反射(1)- 基础

Advantages of Using Reflection:

  • Extensibility Features : An application may make use of external, user-defined classes by creating instances of extensibility objects using their fully-qualified names.
  • Class Browsers and Visual Development Environments : A class browser needs to be able to enumerate the members of classes. Visual development environments can benefit from making use of type information available in reflection to aid the developer in writing correct code.
  • Debuggers and Test Tools : Debuggers need to be able to examine private members on classes. Test harnesses can make use of reflection to systematically call a discoverable set APIs defined on a class, to insure a high level of code coverage in a test suite.

Drawbacks of Reflection

Reflection is powerful, but should not be used indiscriminately. If it is possible to perform an operation without using reflection, then it is preferable to avoid using it. The following concerns should be kept in mind when accessing code via reflection.

  • Performance Overhead : Because reflection involves types that are dynamically resolved, certain Java virtual machine optimizations can not be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts, and should be avoided in sections of code which are called frequently in performance-sensitive applications.
  • Security Restrictions : Reflection requires a runtime permission which may not be present when running under a security manager. This is in an important consideration for code which has to run in a restricted security context, such as in an Applet.
  • Exposure of Internals :Since reflection allows code to perform operations that would be illegal in non-reflective code, such as accessing private fields and methods, the use of reflection can result in unexpected side-effects, which may render code dysfunctional and may destroy portability. Reflective code breaks abstractions and therefore may change behavior with upgrades of the platform.

Trail: The Reflection API

异常

Throwable 可以用来表示任何可以作为异常抛出的类,分为两种: Error 和 Exception,其中 Error 用来表示编译时系统错误。

Exception 分为两种: 受检异常 和 非受检异常。受检异常需要用 try...catch... 语句捕获并进行处理,并且可以从异常中恢复;非受检异常是程序运行时错误,例如除 0 会引发 Arithmetic Exception,此时程序奔溃并且无法恢复。


更详细的内容:

泛型

public class Box<T> {
    // T stands for "Type"
    private T t;
    public void set(T t) { this.t = t; }
    public T get() { return t; }
}

更详细的内容:

注解

Java注解是附加在代码中的一些元信息,用于一些工具在编译、运行时进行解析和使用,起到说明、配置的功能。注解不会也不能影响代码的实际逻辑,仅仅起到辅助性的作用。

更多详细内容:注解Annotation实现原理与自定义注解例子

特性

1. 三大特性

封装、继承、多态

2. Java 各版本的新特性

New highlights in Java SE 8

  1. Lambda Expressions
  2. Pipelines and Streams
  3. Date and Time API
  4. Default Methods
  5. Type Annotations
  6. Nashhorn JavaScript Engine
  7. Concurrent Accumulators
  8. Parallel operations
  9. PermGen Error Removed

New highlights in Java SE 7

  1. Strings in Switch Statement
  2. Type Inference for Generic Instance Creation
  3. Multiple Exception Handling
  4. Support for Dynamic Languages
  5. Try with Resources
  6. Java nio Package
  7. Binary Literals, Underscore in literals
  8. Diamond Syntax

Difference between Java 1.8 and Java 1.7?

更详细的内容:Java 8 特性

3. Java 与 C++ 的区别

Java 是纯粹的面向对象语言,所有的对象都继承自 java.lang.Object,C++ 为了兼容 C 即支持面向对象也支持面向过程。

比较详细的内容:

JavaC++
Java does not support pointers, templates, unions, operator overloading, structures etc. The Java language promoters initially said "No pointers!", but when many programmers questioned how you can work without pointers, the promoters began saying "Restricted pointers." Java supports what it calls "references". References act a lot like pointers in C++ languages but you cannot perform arithmetic on pointers in Java. References have types, and they're type-safe. These references cannot be interpreted as raw address and unsafe conversion is not allowed.C++ supports structures, unions, templates, operator overloading, pointers and pointer arithmetic.
Java support automatic garbage collection. It does not support destructors as C++ does.C++ support destructors, which is automatically invoked when the object is destroyed.
Java does not support conditional compilation and inclusion.Conditional inclusion (#ifdef #ifndef type) is one of the main features of C++.
Java has built in support for threads. In Java, there is a Thread class that you inherit to create a new thread and override the run() method.C++ has no built in support for threads. C++ relies on non-standard third-party libraries for thread support.
Java does not support default arguments. There is no scope resolution operator (::) in Java. The method definitions must always occur within a class, so there is no need for scope resolution there either.C++ supports default arguments. C++ has scope resolution operator (::) which is used to to define a method outside a class and to access a global variable within from the scope where a local variable also exists with the same name.
There is no goto statement in Java. The keywords const and goto are reserved, even though they are not used.C++ has goto statement. However, it is not considered good practice to use of goto statement.
Java doesn't provide multiple inheritance, at least not in the same sense that C++ does.C++ does support multiple inheritance. The keyword virtual is used to resolve ambiguities during multiple inheritance if there is any.
Exception handling in Java is different because there are no destructors. Also, in Java, try/catch must be defined if the function declares that it may throw an exception.While in C++, you may not include the try/catch even if the function throws an exception.
Java has method overloading, but no operator overloading. The String class does use the + and += operators to concatenate strings and Stringexpressions use automatic type conversion, but that's a special built-in case.C++ supports both method overloading and operator overloading.
Java has built-in support for documentation comments (/** ... */); therefore, Java source files can contain their own documentation, which is read by a separate tool usually javadoc and reformatted into HTML. This helps keeping documentation maintained in easy way.C++ does not support documentation comments.
Java is interpreted for the most part and hence platform independent.C++ generates object code and the same code may not run on different platforms.

What are the main differences between Java and C++?

4. JRE or JDK

  • JRE is the JVM program, Java application need to run on JRE.
  • JDK is a superset of JRE, JRE + tools for developing java programs. e.g, it provides the compiler "javac"
ZYNQ Linux环境下PS端I2C驱动OV5640摄像头全流程解析 本文详细解析了在ZYNQ Linux环境下,通过PS端I2C驱动OV5640摄像头的完整流程。内容涵盖从Vivado硬件配置、PetaLinux系统构建、设备树节点添加,到用户空间I2C编程与寄存器配置实战,并提供了关键的调试技巧与常见问题排查方法,帮助开发者快速实现嵌入式视觉应用的传感器配置。 阅读详情

相关推荐

减小伺服电机共振的方法(以松下伺服为例)

嘿 ! 我是【小黄】 , 我们又见面啦 !!! 毕竟技术只有大家交流才会进步嘛 ! 这博客是对自己学习的一点点记录和总结 ,如果您对自动控制感兴趣的话 ,可以关注一下我的动态 , 我们一起学习呀 ! 我们都还年轻 ,我们还有无限可能 。 YES ! 减小伺服电机共振的方法(以松下伺服为例)1. 准备工作:1.1.1 如何推定共振点:1.1.2 测定实操:1.1.3 总结:2. 下期预告: 在我们调试完伺服参数以后机器人运动到某个特定位置会产生振动或异响,我们要做的就是消除这个异响保..

在下小黄的博客 1万+

java基础细节题

String 被声明为 final,因此它不可被继承。它的底层是通过final数组实现的,因此初始化后就不可以更改,有一下好处 声明数据 对于基本类型,final 使数值不变; 对于引用类型,final 使引用不变,也就不能引用其它对象,但是被引用的对象本身是可以修改的。 声明方法不能被子类重写。 private 方法隐式地被指定为 final,如果在子类中定...

在杯子里放零食的博客 254

obisidian插件之【templater】模板的中文说明书

Templater 是一种模板语言,可让您将变量和函数结果插入到笔记中。它还允许您执行操作这些变量和函数的 JavaScript 代码。使用 Templater,您将能够创建强大的模板来自动执行手动任务。

m0_55795604的博客 1万+

java基础知识面试题目

八大基本数据类型基本数据类型转换关系:byte→short(char)→int→long→float→double所谓包装类,就是能够直接将简单类型的变量表示为一个类,在执行变量类型的相互转换时,我们会大量使用这些包装类。以下用途 new Integer(123) 与 Integer.valueOf(123) 的区别在于:缓冲池包装类型内存使用 private static class IntegerCache,声明一个内部使用的缓存池在 jdk 1.8 所有的数值类缓冲池中,Integer 的缓冲池

编程大魔王 371

【实战指南】利用CAN适配器高效调试CAN总线通信

本文提供了一份利用CAN适配器高效调试CAN总线通信的实战指南。文章从硬件连接、终端电阻配置、软件参数设置等基础环节入手,详细解析了CAN适配器作为关键调试工具的工作原理与使用方法,并针对常见的通信故障提供了系统化的问题排查思路,帮助工程师快速打通通信链路,提升调试效率。

weixin_28285943的博客 412

Postman调试海康ISAPI接口全记录:从鉴权失败到成功修改设备名的踩坑指南

本文详细记录了使用Postman调试海康ISAPI接口的全过程,从鉴权失败到成功修改设备名的实战经验。涵盖Digest认证机制、XML请求体构造、常见错误排查及代码实现过渡,帮助开发者高效解决海康设备集成中的各种问题。

weixin_42620913的博客 660

Java:Java Packages(Built-in & User-defined)Java包详解

1 Java Packages 介绍 Java 包可划分为两类: Built-in Packages (packages from the Java API) User-defined Packages (create your own packages) 1.1 Built-in Packages Java API 是一个预编写类库,可以免费使用,包含在 Java开发环境中。 该库包含用于管理输入,数据库编程等的组件。 该库分为包packages和类classes。这意味着可以导入单个类(及其

Xminyang的博客 678

从零实现地震波场模拟:交错网格有限差分法核心代码精讲

本文详细介绍了从零实现地震波场模拟的核心技术,重点讲解了交错网格有限差分法的实现过程。通过速度-应力弹性波方程的离散化处理,结合代码实例演示了应力与速度更新的关键步骤,并分享了震源加载、稳定性条件等实用技巧,为计算地球物理学研究提供实践指导。

weixin_42556197的博客 410

Java8新特性(五)Nashorn javascript引擎

在Java8之前,如果要调用js语言是用Rhino调用,Java8只会自动升级到Nashorn,下面有一个例子 //获取脚本引擎的对象 ScriptEngineManager sem = new ScriptEngineManager(); ScriptEngine engine = sem.getEngineByName("javascript"); System.out.println(...

terrybg 1万+

【数据可视化-77】中国历年GDP数据可视化分析:Python + Pyecharts 深度洞察(含完整数据、代码)

通过上述可视化分析,我们可以清晰地看到中国历年GDP的变化趋势和产业构成。玫瑰图展示了2024年的产业构成,地图和柱状图展示了GDP的时空分布,双轴折线图和雷达图则分别展示了GDP总量与人均GDP的变化以及各行业的GDP贡献。希望这篇文章能帮助您更好地理解和分析中国历年GDP数据。如果您有任何问题或建议,欢迎在评论区留言!🎉。

qq_38614074的博客 1469

BOSS直聘招聘端自动化识别策略调整(20250905)

2025年9月BOSS直聘调整账号登录策略,禁止使用辅助工具,违者将禁用PC端和网页端2个月。作者认为这一政策可能调整,因为AI辅助已成趋势,严格限制会影响付费客户。企业使用辅助工具的主要原因是平台推送的候选人匹配度低,导致沟通成本高。虽然部分企业滥用功能骚扰求职者,但BOSS直聘仍需依赖这些付费客户。新规可能得罪大客户,但只要有需求,市场总会找到应对方案。

企智软件 827

java基础教程

java基础教程

ruijungao的博客 628

飞牛fnNAS虚拟机开启OVS导致失联的解决

摘要:用户在使用飞牛NAS时发现开启OVS网络功能后导致NAS失联。通过多种尝试(包括开关OVS、更换系统版本、手工配置、更换网卡、处理器检查等)后发现,OVS启用状态下DHCP无法获取IP地址,手动设置IP可暂时恢复网络。但重启后问题依旧,初步判断为OVS功能存在bug。目前临时解决方案是在需要时手动开关OVS,或考虑其他虚拟化方案。用户计划后续探索替代方案,并等待官方修复该问题。

dgnankai的专栏 4334

【详细+超基础】Java-学习笔记

JAVA简介 Java是半编译半解释性语言,它将.java的源程序文件编译成拓展名为.class的字节码文件,字节码文件可以在任何一台装有JVM虚拟机的操作系统上运行,从而达到“一次编译,随处运行”的目的。 Java 特点:简单的 面向对象的 分布式的 解释执行的 健壮的 安全的 结构中立的 可移植的 高效率的 多线程的 动态的和跨平台的编程语言。......

请你喝杯Java 1万+

深度学习工具包 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")

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

java点赞_java实现点赞功能示例

最近做了一个评论的点赞功能,感觉有必要记录一下。思路:点赞功能,看起来挺简单,但是做的高效稳定还是需要一些处理。归纳思路如下:1.点赞接口要利用redis做点赞次数限制,比如一分钟之内最多点赞或取消点赞四次2.点赞是很高频随兴的操作,最好不要直接操作数据库,先把点赞信息放入redis缓存,然后跑定时任务每15秒去同步到数据库,同步完之后把同步好的信息批量从redis删除。3.把点赞信息放入redi...

weixin_36315943的博客 2954

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

java点赞功能

赞   //zancount是我数据库的赞数 ${i.zanCount==0?"":i.zanCount}  function zan2(luntanid,zan) { //当前赞的人 var loginid=$(".loginid").val(); $.ajax({ url:"luntan/zan",//跳转界面 data:{ luntanid:lu

杏杏杏妹子的博客 7254

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

java 点赞_Java开发利用Redis是如何实现点赞、取消点赞的?

本文基于 SpringCloud, 用户发起点赞、取消点赞后先存入 Redis 中,再每隔两小时从 Redis 读取点赞数据写入数据库中做持久化存储。点赞功能在很多系统中都有,但别看功能小,想要做好需要考虑的东西还挺多的。点赞、取消点赞是高频次的操作,若每次都读写数据库,大量的操作会影响数据库性能,所以需要做缓存。至于多久从 Redis 取一次数据存到数据库中,根据项目的实际情况定吧,我是暂时设了...

weixin_42109925的博客 1829

java实现点赞(顶)功能

java实现点赞(顶)功能 需求分析 分析: 1.必须先登录,否则提示 2.第一次点赞(顶),点赞操作,点赞数+1,提示顶成功 2.第二次点赞(顶),没有操作,提示今天顶过了 --------------------------------------------- 核心问题: 1>怎么区分当前请求时顶成功操作(第一次顶)还是今天已经顶过(第二次顶) 2>怎么考虑今天已顶过 ----------------------------------------------

三少 6754

JAVA自动爬取优快云用户数据并文章点赞

爬取用户 某天,我发现我的文章被某个用户点赞了。欣喜之下,把那边文章重新校核更改一遍,接着进入这个点赞我的用户看看,结果发现他近期的博客是一些爬虫的实战。我想,我那篇文章,应该是他做的一个小程序批量加载用户信息并给文章点赞。我觉得这是一个有点意思的事,于是用java实现csdn批量爬取用户名并点赞。其中批量爬取用户名的思路借鉴这位大神的这篇博文GO+Selenium批量关注优快云 1 (如何获取...

咸鱼老罗的博客 1829

LeetCode 1542. 找出最长的超赞子字符串

给你一个字符串s。请返回s中最长的的长度。s5"24241" 是最长的超赞子字符串,交换其中的字符后,可以得到回文 "24142"16"213123" 是最长的超赞子字符串,交换其中的字符后,可以得到回文 "231132"s = "00"2提示 1提示 2提示 3。

m0_56090828的博客 1349

Redis是如何实现点赞、取消点赞的?,Java常见编程笔试题

阿里伤透我心,疯狂复习刷题,终于喜提offer 哈哈~好啦,不闲扯了1、JAVA面试核心知识整理(PDF):包含JVMJAVA集合JAVA多线程并发,JAVA基础,Spring原理微服务,Netty与RPC,网络,日志,ZookeeperKafkaRabbitMQ,Hbase,MongoDB设计模式负载均衡数据库一致性哈希JAVA算法数据结构,加密算法,分布式缓存,Hadoop,Spark,Storm,YARN,机器学习,云计算共30个章节。2、Redis学习笔记及学习思维脑图。

2301_79098686的博客 894

点赞功能详解

点赞功能详解 先讲讲点赞功能的实现。 首先,你得为点赞功能建立一个表,表里需要记录点赞的topic的ID,已经点赞的人的id. 对应的实体类如下: package com.example.demo.domain; import javax.persistence.*; import java.io.Serializable; import java.util.Date; /** * @Cla...

untilyouydc 7956

Redis 基础 - 点赞/点赞排行榜

点赞/点赞排行榜

PurineKing之博客 762

15 种超赞的 MyBatis 写法

本文介绍了15种提升MyBatis数据库操作效率的实用技巧,包括:1)优化批量操作使用<foreach>标签;2)动态SQL构建方法;3)多条件分支查询实现;4)SQL语句优化策略;5)自动生成主键配置;6)注解方式简化CRUD;7)高级对象关系映射;8)MyBatis-Plus集成方案。这些方法涵盖了从基础到进阶的MyBatis使用场景,能显著提高开发效率和系统性能。文章通过具体代码示例展示了每种写法的实际应用,为开发者提供了可落地的技术方案。

IT枫斗者的博客 623

在力扣阅读了大佬灵茶山艾符对“找出最长的超赞子字符串”算法题的题解后的个人理解。

此情形下,子串[j + 1, i]中 0 ~ 9 的出现次数均为偶数,pre[ [j + 1, i] ]的二进制数中各位均为0,所以pre[ [j + 1], i] == 0 == pre[i] ^ pre[j] ——>pre[i] ^ 0 == pre[j]。(2)pre[ [j + 1, i] ]的值的二进制形式表示字符串s的下标范围在[j + 1, i]的子串中 0 ~ 9 分别出现的次数的奇偶性,分别用pre的二进制形式中的0 ~ 9位来表示,出现次数为奇数则用1表示,出现次数为偶数用0表示。

Noah_hy的博客 902

java使用Redis实现点赞功能

疑问 当看到这个标题,可能会有些大佬有点模糊,因为为什么不用数据库去实现,而用redis来实现这个功能,那我们可以一起来思考一下。 为什么实现redis,而不用数据库 先从安全方面来讲,如果使用数据库,假如用户频繁点赞,取消点赞这些操作的话,那么会给数据库造成压力,如果使用缓存的话,那么压力不会那么大。 从效率方面考虑,redis数据存在与内存,所以速度收到内存影响,数据库存在与硬盘,速度没redis快。 从功能方面考虑,redis只支持几种数据结构,没用数据库支持的多。 Redis几种数据结构的适用场

kires的博客 4524
上一篇: redis学习总结(超赞!!!)
下一篇: 《大规模分布式存储系统》学习总结(超赞!!!)
普通网友
博客等级 码龄9年 489粉丝 29原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值