Java大牛养成记
Java大牛养成记
工一木子
Talk is cheap,show me the code!
展开
-
计算1+3+...+99的和
public class OddSum{ public static void main(String[] args) { /* 需求: 计算1+3+...+99的值,并打印输出 */ long result = 0;//存放奇数的和 for(int i=1;i原创 2016-06-30 18:52:55 · 1782 阅读 · 0 评论 -
Object类之equals方法
class Cat{ int color; int height; int weight; public boolean equals(Object obj) { if(obj == null) return false; else {原创 2016-07-05 21:56:21 · 4604 阅读 · 0 评论 -
面向对象之多态
class Pet{ private String name; Pet(String name) { this.name = name; } void enjoy() { System.out.println("宠物的叫声"); }}class Dog extends Pet{原创 2016-07-06 16:24:38 · 338 阅读 · 0 评论 -
面向对象之接口
interface Singer{ void sing();}interface Painter{ void paint();}abstract class Person{ private String name; abstract void sleep();}class Student extends Person im原创 2016-07-06 16:25:32 · 294 阅读 · 0 评论 -
引用类型变量的转型
class Animal{ private String name; Animal(String name) { this.name = name; }}class Dog extends Animal{ private String furColor; Dog(String name,String fu原创 2016-07-06 16:27:42 · 363 阅读 · 0 评论 -
面向对象之抽象
abstract class Animal{ abstract void enjoy();}class Dog extends Animal{ void enjoy() { System.out.println("狗叫!!!!"); }}class Cat extends Animal{ void en原创 2016-07-06 16:28:52 · 336 阅读 · 0 评论 -
java之异常处理机制
class MyException extends Exception{ private int id; MyException() { System.out.println("我是自定义异常"); } MyException(String msg,int id) { super(msg);原创 2016-07-06 19:47:58 · 276 阅读 · 0 评论 -
神奇的java socket编程
简单的服务器与客户端之间的通信:服务器端:import java.net.*;public class TCPServer{ public static void main(String[] args) throws Exception { ServerSocket ss = new ServerSocket(6666); S原创 2016-07-17 21:37:13 · 310 阅读 · 0 评论 -
数组初体验
public class TestArray{ public static void main(String[] args) { int[] a; a = new int[5]; /*for(int i=0;i { System.out.print(a[i]+" ");原创 2016-07-07 17:22:20 · 315 阅读 · 0 评论 -
数组之args参数
public class TestArgs{ public static void main(String[] args) { /* 需求:在执行java程序的时候,输入三个命令行参数,进行常见的四则运算 */ /*if(args.length == 3) {原创 2016-07-07 17:22:53 · 1019 阅读 · 0 评论 -
数组拷贝
//import java.lang.System;public class TestArrayCopy{ public static void main(String[] args) { int[][] a = new int[3][]; int[][] b = new int[3][]; a[0] = new i原创 2016-07-07 17:24:13 · 371 阅读 · 0 评论 -
数组之系统排序函数
import java.util.Arrays;public class TestArray1{ public static void main(String[] args) { /* 需求:从命令行的参数传给一个整型数组5个数 将这5个数存到整型数组中 将这5个数进行排序(原创 2016-07-07 17:23:35 · 630 阅读 · 0 评论 -
数组之选择排序
class TestSortNum{ public static void main(String[] args) { /* 需求:通过命令行参数输入几个数字,进行排序 */ int[] a = new int[args.length]; for(int i=0;i原创 2016-07-07 17:26:22 · 448 阅读 · 0 评论 -
java之枚举类型
public class TestEnum{ public enum MyColor {red,blue,yellow}; public static void main(String[] args) { //Enum MyColor = {red,blue,yellow};//error //enum MyColor {red原创 2016-07-07 23:44:57 · 403 阅读 · 0 评论 -
java之判断文件存在
//import java.io.File;package wzq;import java.io.*;public class TestFile{ public static void main(String[] args) { String separator = File.separator; String fileNam原创 2016-07-07 23:46:24 · 504 阅读 · 0 评论 -
java之注释
代码注释是架起程序设计者与程序阅读者之间的通信桥梁,最大限度的提高团队开发合作效率。也是程序代码可维护性的重要环节之一。所以我们不是为写注释而写注释。下面说一下我们在诉求网二期开发中使用的代码注释规范,供大家参考下。原则:1、注释形式统一在整个应用程序中,使用具有一致的标点和结构的样式来构造注释。如果在其它项目中发现它们的注释规范与这份文档不同,按照这份规范写代码,不要试图在既成的转载 2016-07-08 19:22:59 · 277 阅读 · 0 评论 -
javase专题--日期处理--1
import java.sql.Connection;import java.sql.Date;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.Statement;import java.text.SimpleDateFormat;public class TestDat原创 2016-08-02 21:03:33 · 341 阅读 · 0 评论 -
MySQL版本,MySQL连接jdbc驱动版本与JDK版本问题
昨天在执行mybatis逆向工程时,在运行主函数时,出现了如下异常:这个问题在百度,谷歌都搜不到满意的答案。而且看网上的mybatis逆向工程和我的代码一模一样,就很纳闷了。而且看视频中,老师也是直接运行无问题。今晚下班,又仔细看了下出错信息,看到有几个是MySQL驱动包抛出的异常。就有疑问:是不是因为MySQL版本和MySQL驱动包版本不一致导致。因为当时我的MySQL版本是8.原创 2017-07-25 21:27:18 · 21119 阅读 · 6 评论 -
Object类的toString方法
class Dog{ public String toString() { return "I'm a hot dog!"; }}public class TestToString{ public static void main(String[] args) { Dog d = new Dog(原创 2016-07-05 21:55:26 · 1643 阅读 · 0 评论 -
Java开发必备:java帮助文档网址下载或在线帮助
J2SE DK & API下载————————-http://Java.sun.com/j2se/1.3/download.htmlhttp://java.sun.com/j2se/1.4.2/download.htmlhttp://java.sun.com/javase/downloads/index_jdk5.jsphttp://java.sun.com/javase/do转载 2016-07-05 21:08:35 · 4003 阅读 · 1 评论 -
计算1!+2!+...+10!的值
public class FactorialSum{ public static void main(String[] args) { /* 需求: 计算1!+2!+...+10!的和并打印输出 */ long result = 0;//用于存放累加的和 long f原创 2016-06-30 18:53:57 · 3694 阅读 · 0 评论 -
while打印1到9的值
public class TestWhile{ public static void main(String[] args) { /* 需求: 用while循环打印出1到9的值 */ int i = 1; while(i {原创 2016-06-30 22:59:30 · 1098 阅读 · 0 评论 -
do...while打印1到9的值
public class TestDoWhile{ public static void main(String[] args) { /* 需求: 用do...while输出1到9的值 */ int i = 1; do {原创 2016-06-30 23:00:18 · 843 阅读 · 0 评论 -
break的作用
public class TestBreak{ public static void main(String[] args) { /* 需求:计划输出1到9的值,到4停止输出 目的:测试break的作用 输出结果: i=1 i=2 i=3原创 2016-06-30 23:17:40 · 542 阅读 · 0 评论 -
continue的作用
public class TestContinue{ public static void main(String[] args) { /* 需求:输出1到9的值,除了4之外 目的:测试continue的用法 输出结果: i=1 i=2 i=3原创 2016-06-30 23:18:28 · 670 阅读 · 0 评论 -
1.打印101到200内的素数(质数)【用双层循环实现】&2.打印1到100内前5个可以被3整除的数
public class IsPrime{ public static void main(String[] args) { /* 需求: 打印101到200内的素数(质数)【用双层循环实现】 */ /*for(int i=101;i { b原创 2016-07-02 12:54:22 · 2007 阅读 · 0 评论 -
方法(函数)测试
public class TestMethod{ public static void main(String[] args) { //m(); //m1(10); //m2(10,20); //System.out.println(m3(100,200)); testFor();原创 2016-07-02 12:56:41 · 373 阅读 · 0 评论 -
测试switch
public class TestSwitch{ public static void main(String[] args) { /* 需求:测试switch的用法 */ int i = 3; switch(i) { case 1:原创 2016-07-02 12:57:54 · 4029 阅读 · 0 评论 -
递归与斐波那契数列
public class TestFib{ public static void main(String[] args) { /* 需求:用递归方法计算斐波那契数列第五个数的值 斐波那契数列的规律: f = 1(n=1,2) f = f(n-1)+f(n-2) */原创 2016-07-02 14:21:36 · 395 阅读 · 0 评论 -
面向对象之第一个程序
class Person{ int id; int age; void setAge(int _age) { age = _age; } void showAge() { System.out.println(age); } Person(int _id,int _ag原创 2016-07-02 18:07:50 · 313 阅读 · 0 评论 -
内存分析之模拟一个点并进行简单的操作
//Point类class Point{ //Point类的属性 int x; int y; int z; /* 可以简写为:int x,y,z; */ //构造函数,为点的各个坐标赋初值 Point(int _x,int _y,int _z) { x = _x;原创 2016-07-03 12:05:15 · 344 阅读 · 0 评论 -
面向对象之函数重载
class Person{ int id,age; Person() { id = 0; age = 10; } Person(int _id) { id = _id; age = 20; } /*Person(int _age)原创 2016-07-03 17:52:34 · 691 阅读 · 0 评论 -
求一个圆的面积及判断一个点是否在圆内
class Point{ private double x; private double y; //double x; //double y; Point() { x = 0; y = 0; } Point(double _x,double _y) {原创 2016-07-03 21:41:11 · 4716 阅读 · 0 评论 -
java之权限控制
class Test{ private int i = 0; int j = 0; protected int k = 0; public int l = 0;}public class TestAccess{ public static void main(String[] args) { Test t原创 2016-07-05 11:58:19 · 378 阅读 · 0 评论 -
java之方法重写
class FatherClass{ int value = 0; void f() { value = 100; System.out.println("Father Classs :value="+value); }}class ChildClass extends FatherClass{原创 2016-07-05 11:59:20 · 329 阅读 · 0 评论 -
java之子类中的构造方法
class SuperClass{ int i; /*this(int n) { i = n; }*/ /* TestSuperSub.java:4: 错误: 非法的类型开始 this(int n) ^1 个错误 */ SuperClass()原创 2016-07-05 12:00:26 · 741 阅读 · 0 评论 -
java继承中的构造方法及this,super的使用
class Person{ private String name; private String location; Person(String name) { this.name = name; this.location = "beijing"; } Person(String name,St原创 2016-07-05 19:01:20 · 1177 阅读 · 0 评论 -
MySQL的安装方式
一般在Windows上安装软件,一般都是执行msi或者exe文件,今天无意中学到了也可以像在Linux下使用命令装软件。今天拿zip版的mysql做例子。详情请参考这位仁兄的博客,下面是地址:http://www.cnblogs.com/jamespan23/p/5953133.html整体思路是:1.解压文件,放到磁盘的某个位置。我是放在了D盘下的MySQL文件夹下,这个文件夹是自己原创 2017-07-25 21:33:42 · 410 阅读 · 1 评论