catalogue
1. Shortcut keys for IDEA tools and some simple settings
2. Shortcut keys for eclipse tools and some simple settings
2.1. File related shortcut keys
2.2 shortcuts commonly used when writing code
3. Basic exercises of Java program
1. Shortcut keys for IDEA tools and some simple settings
1) Font setting file -- > setting -- > Enter font -- > to set font style and size;
2) Fast generate main method: psvm
3) Quickly generate sys out. println(): sout
4) Note that IDEA is saved automatically, and Ctrl + S is not required
5) Delete a row: Ctrl + Y
6) Run: right click the code - > run, click the green arrow on the left side of the code Ctrl + Shift + F10
7) Expand and close the list of the left window: the left arrow closes; The right arrow opens; Up and down arrows move;
8) Exit any window Esc key
9) Any new / new / added shortcut: Alt + Insert
10) Window becomes larger and smaller: Ctrl + Shift + F12
11) Toggle Java program Alt + left and right arrows
12) Toggle window Alt + label (open, close)
13) Prompt method parameters: Ctrl + P
14) Copy the cursor current line code to the next line: Ctrl + D
15) Locate the method / property / variable, pause the cursor under a word, press Ctrl, underline, and click
2. Shortcut keys for eclipse tools and some simple settings
2.1. File related shortcut keys
1) Create a new project, file, folder, etc. Ctrl + N
2) Shortcut in dialog box Alt + underlined letter
3) Window maximize / restore Ctrl + M
4) Open the properties window of the selected project, package, file, etc. Alt + Enter
5) Run program Ctrl + F11
6) Running program F11 in debugging mode
7) Rename project name, file name, method name, variable name right click - > refactor - > rename Alt + Shift + R F2
8) Rename project name and file name F2
9) Open the edit window to view the directory Ctrl + E
10) Switch to the previous window of the current editing window Ctrl + Page Up
11) Switch to the next window of the current editing window Ctrl + Page Down
2.2 shortcuts commonly used when writing code
1) Copy up (down) the contents of the line where the cursor is located or the selected contents Ctrl + Alt + up (down) key
2) Move up (down) the content of the line where the cursor is located or select the content Alt + up (down) key
3) Delete current line / cursor line Ctrl + D
3) Add a space under the line where the cursor is located Shift + Enter
4) Error giving solution Ctrl + 1
5) Auto prompt Alt +?
3. Basic exercises of Java program
3.1 topic 1: Vehicle Driving
requirement:
Please define a vehicle class with attributes:
1) Speed,
2) Volume (size),
3) Method move (),
4) Set speed (int speed,),
5) Accelerate speedUp(),
6) Decelerate speedDown();
Finally, instantiate a Vehicle object in main() in the test class Vehicle, initialize the value of speed and size through the method, print it, and change the speed by accelerating and decelerating;
public class HelloWorld { public static void main(String[] args) { //Object creation by parameterless construction method Vehicle v = new Vehicle(); //Creating objects with parametric construction methods Vehicle v1 = new Vehicle(100.0,5.0); //Assignment by set method v.setSpeed(100.0); System.out.println("oldSpeed : " + v.getSpeed()); v.setSize(5.0); //Call acceleration method v.speedUp(10.0); System.out.println("addSpeed : " + v.getSpeed()); //Call deceleration method v.speedDown(5.0); System.out.println("downSpeed : " + v.getSpeed()); } } class Vehicle { private double speed; private double size; //Nonparametric construction method public Vehicle() { } //Parametric construction method public Vehicle(double speed, double size) { this.speed = speed; this.size = size; } public double getSpeed() { return speed; } //Method of setting speed public void setSpeed(double speed) { this.speed = speed; } public double getSize() { return size; } public void setSize(double size) { this.size = size; } //Moving method of vehicle public void move() { System.out.println("The bus started"); } //Acceleration method public void speedUp(double addSpeed) { //Add on the original basis //int oldSpeed = this.getSpeed() this.setSpeed(this.getSpeed() + addSpeed); } //Deceleration method public void speedDown(double delSpeed) { //Subtract from the original //int oldSpeed = this.getSpeed() this.setSpeed(this.getSpeed() - delSpeed); } }
3.2 topic 2: Calculator
Requirements:
1) Define a class named Number where two integer data members n1 and n2 should be declared private.
2) Write the initial values of construction method assignment n1 and n2;
3) Define the public instance methods of adding addition(), subtracting substitution (), multiplying multiplication(), and dividing division() for this class;
4) Add, subtract, multiply and divide the two member variables respectively;
public class JiSuanQi { public static void main(String[] args) { Number n1 = new Number(); Number n2 = new Number(5,41); Number n3 = new Number(82,6); Number n4 = new Number(24,6); n1.addition(); n2.subration(); n3.multiplication(); n4.division(); } } class Number { private int n1; private int n2; public Number(int n1, int n2) { this.n1 = n1; this.n2 = n2; } public Number() { this(10,20); } public void setN1(int n1) { this.n1 = n1; } public void setN2(int n2) { this.n2 = n2; } public int getN1() { return n1; } public int getN2() { return n2; } public void addition(){ System.out.println(n1 + "+" + n2 + "=" + (n1+n2)); System.out.println(this.getN1() + "+" + this.getN2() + "=" + (this.getN1() + this.getN2())); } public void subration(){ System.out.println(n1 + "-" + n2 + "=" + (n1-n2)); System.out.println(this.n1 + "-" + this.getN2() + "=" + (this.getN1() - this.getN2())); } public void multiplication(){ System.out.println(n1 + "*" + n2 + "=" + (n1*n2)); System.out.println(n1 + "*" + n2 + "=" + (getN1() * getN2())); } public void division(){ System.out.println(n1 + "/" + n2 + "=" + (n1/n2)); } }
3.3 topic 3: People Message
requirement:
1) Define a human People. This class should have two private attributes: name and age;
2) Define construction methods to initialize data members;
3) Define the display method to print out the name and age;
4) Create an instance of the human object in the main method, and then display the information;
public class People { public static void main(String[] args) { Peason p = new Peason("Sam",18); p.display(); Peason p2 = new Peason(); p2.setName("Zhang San"); p2.display(); } } class Peason{ private String name; private int age; public void display(){ System.out.println("name:" + this.getName() + "," + "age: " + this.age); } public Peason() { } public Peason(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public void setAge(int age) { this.age = age; } public int getAge() { return age; } }
3.4 topic 4: Add Time
requirement:
1) The class defined as MyTime should have three integer members: hour minute second;
2) In order to ensure data security, these three member variables should be declared private;
3) Define a construction method for MyTime class to initialize member variables when creating objects;
4) Then define the display method to print out the time information;
5) Add the following methods to the MyTime class:
addSecond(int sec)
addMinute(int min)
addHour(int hou)
subSecond(int sec)
subMinute(int min)
subHour(int hou)
public class Time { public static void main(String[] args) { MyTime t1 = new MyTime(13,20,15); t1.display(); t1.addSecond(121); t1.display(); } } class MyTime{ private int hour; private int minute; private int second; public void addSecond(int sec){ int oldSec = this.getSecond(); int newSec = oldSec +sec; if(newSec < 60){ this.setSecond(newSec); }else if(newSec == 60){ this.addMinute(1); this.setSecond(0); }else{ this.addMinute(newSec / 60); this.setSecond(newSec % 60); } } public void addMinute(int min) { this.setMinute(this.getMinute() + min); }//Since the following methods are similar, it will not be repeated to solve mathematical problems //The second processing method can also be used to deal with such problems public void addHour(int hou){ } public void subSecond(int sec){ } public void subMinute(int min){ } public void subHour(int hou){ } public void display(){ System.out.println(this.getHour() + "Time" + this.getMinute() + "branch" + this.getSecond() + "second"); } public void setHour(int hour) { this.hour = hour; } public void setMinute(int minute) { this.minute = minute; } public void setSecond(int second) { this.second = second; } public int getHour() { return hour; } public int getMinute() { return minute; } public int getSecond() { return second; } public MyTime() { } public MyTime(int hour, int minute, int second) { this.hour = hour; this.minute = minute; this.second = second; } }