DALLASCAO.COM

Site of Cao Shouguang, English to Chinese translator

learn java: set classname as method type

learn java: set  classname as method type
public class SavingsAccount { /** * output: * * 3000 * 7000 * 10000 */ int balance; static int totalBalance; //constructor SavingsAccount(int balance) { this.balance = balance; } //Classname as method type. User return this SavingsAccount deposit(int amount) { balance += amount; totalBalance = totalBalance + balance; return this; } //method void type void printBalance() […]Read More

Learn java: static variable

Learn java: static variable
public class Car { /** * Car.counter will output 2 */ String make; String model; int numDoors; static int counter; // constructor, applying to all cars Car(String make, String model, int numDoors) { this.make = make; this.model = model; this.numDoors = numDoors; counter++; } //constructor set default numDoors to 4 Car(String make, String model) { […]Read More

Learn java: Contructors vs methods

Learn java: Contructors vs methods
public class Car { /**Output: My car has 4 doors Your car has 3 doors Your car is driven by your wife */ String make; String model; int numDoors; // constructor, applying to all cars Car(String make, String model, int numDoors) { this.make = make; this.model = model; this.numDoors = numDoors; } //constructor set default […]Read More

Learn Java: print an asterisk tower

Learn Java: print an asterisk tower
/** Print a asterisk tower. Learn Java practice OUTPUT * *** ***** ******* ********* *********** ************* *************** ***************** ******************* @author Yifan Chao */ public class Ast { /** app entry point */ public static void main(String[] args) { for (int counter1 = 1; counter1Read More

Solve “too many open files” error on ubuntu/debian

Solve “too many open files” error on ubuntu/debian
Use cat /proc/sys/fs/file-nr to check open file numbers vs max numbers. printf " fs.file-max = 655350" >> /etc/sysctl.conf sysctl -p /etc/sysctl.conf printf " * soft nofile 655350 * hard nofile 655350" >> /etc/security/limits.conf printf " session required pam_limits.so" >> /etc/pam.d/su printf " session required pam_limits.so" >> /etc/pam.d/common-session printf " ulimit -n 655350" >> /root/.bashrc printf […]Read More