随笔分类 - Java
摘要:public class Main { public static void main(String[] args) { String words = "One Two Three Four"; int countWords = words.split("\\s").length; System.o
阅读全文
摘要:Java File Handling The File class from the java.io package, allows us to work with files. import java.io.File; // Import the File class File myObj = n
阅读全文
摘要:import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<Integer> numbers = new ArrayList<Integer>(); number
阅读全文
摘要:Threads allows a program to operate more efficiently by doing multiple things at the same time. Creating a Thread There are two ways to create a threa
阅读全文
摘要:Pattern Class - Defines a pattern (to be used in a search) Matcher Class - Used to search for the pattern PatternSyntaxException Class - Indicates syn
阅读全文
摘要:try and catch 确切的说这应该是Exception。因为Error是指Java虚拟机无法解决的严重问题,如stack溢出,堆溢出... Use try and catch: 可以写多个catch来捕捉不同的exception类型 public class Main { public st
阅读全文
摘要:Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects. Primitive Data TypeWrapper Class byte Byte short Short int
阅读全文
摘要:An Iterator is an object that can be used to loop through collections, like ArrayList and HashSet. // Import the ArrayList class and the Iterator clas
阅读全文
摘要:A HashSet is a collection of items where every item is unique, and it is found in the java.util package: import java.util.HashSet; // Import the HashS
阅读全文
摘要:A HashMap however, store items in "key/value" pairs, and you can access them by an index of another type (e.g. a String). Create a HashMap object call
阅读全文
摘要:The LinkedList class is almost identical to the ArrayList: import java.util.LinkedList; public class Main { public static void main(String[] args) { L
阅读全文
摘要:The ArrayList class is a resizable array, which can be found in the java.util package. The difference between a built-in array and an ArrayList in Jav
阅读全文
摘要:Java does not have a built-in Date class, but we can import the java.time package to work with the date and time API. ClassDescription LocalDate Repre
阅读全文
摘要:The Scanner class is used to get user input, and it is found in the java.util package. To use the Scanner class, create an object of the class and use
阅读全文
摘要:An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables). enum Level { LOW, MEDIUM, HIGH } You
阅读全文
摘要:Another way to achieve abstraction in Java, is with interfaces. An interface is a completely "abstract class" that is used to group related methods wi
阅读全文
摘要:Abstraction can be achieved with either abstract classes or interfaces. The abstract keyword is a non-access modifier, used for classes and methods: A
阅读全文
摘要:In Java, it is also possible to nest classes (a class within a class). The purpose of nested classes is to group classes that belong together, which m
阅读全文
摘要:What are Classes and Objects? A class is a template for objects, and an object is an instance of a class. Static vs. Public we created a static method
阅读全文
摘要:public class Main { static void myMethod() { System.out.println("I just got executed!"); } public static void main(String[] args) { myMethod(); } } //
阅读全文

浙公网安备 33010602011771号