Eclipse Development tools for Java Basics 11

“This is the 11th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021.”

About the author

  • The authors introduce

🍓 Blog home page: author’s home page 🍓 Introduction: 🥇, a high quality creator in JAVA field, 🎓, a junior in college, participated in various provincial and national competitions and won a series of honors. 🍓 pay attention to me: pay attention to my learning materials, document download all have, regularly update the article every day, inspirational to do a JAVA senior program ape 👨💻.


The Eclipse history

Eclipse translates as “Eclipse” in Chinese and refers to the all-engulfing light, so this extremely provocative name is actually aimed at SU Nian Company. SUN has never recovered from the dotcom slump since 2000, and most awkwardly for SUN, it doesn’t make much money from hardware, and Java, the programming language for software, isn’t SUN’s money maker, it’s just a copyrighted company.

The IDE (Integrated Development Environment) for Java itself has undergone some historical tweaks.

In 1995, Java was born, but SUN announced very loudly that we would not build our own ides and would sell them to other third-party companies.

After Java came into being, Borland company started Java IDE production, so later JBuilder became the only choice for Java development (do not choose JBuilder use Notepad, IDEA,JCREATOR,EDIPLUS… .). The latter two were not normal until after JBuilderX;

Eclipse came after 2003, and SUN’s own development tool, NetBeans, came after 2004

And from the whole domestic Java development model has been changing;

Deluxe architecture: operating system + database + middleware + development tools + programming language;

System: IBM AIX + IBM DB2 + WwbsphereApplicationServer + WSAD;

Super miscellaneous system: UNIX+Oracle+Weblogic+JBuilder;

Free architecture: Linux+MySQL+Tomcat/JBoss+Eclipse;

The earliest overlord of development tools was JBuilder, but unfortunately, Borland closed down in 2006, because there was no open source trend of dry voice, because there were a lot of learners, Borland might not need such professional tools, so there were problems in the market at that time. Finally, Borland Technology Department set up a separate technology company to continue the research of JBuilder, but today JBuilder has been basically unusable, completely replaced by Eclipse.

Eclipse was developed by IBM and later transferred to today’s Eclipse organization for the promotion of open source projects. Eclipse was formerly known as IBM VisualAge, and THEN IBM developed the WSAD tool based on the 1.0 model of Eclipse. Eclipse itself is free, but it charges for plug-ins (China doesn’t even charge for plug-ins), and it has the following basic components: JDT,JUNIT test tool,CVS client, plug-in development, users can directly go to www.eclipse.org to download the latest version of Eclipse, JUNO (JUNO, the name of the planet) version, and Eclipse can now be directly unzipped after use, no separate installation, is pure green version.

When our Java project resume is completed, we can find two folders in the project’s directory:

Src: saves all *.java programs by package name;

Bin: saves all generated *. Class files by package name.

Let’s resume a new class: TestDemo.java

One of the biggest benefits of using Eclipse itself is that it is easy to write tips, and every time a.java program is saved, Eclipse automatically compiles it to a.class file.

There are also code generation tools available in Eclipse, such as the following simple classes

package com.sxau;

public class Person {
	private String name;
	private int age;
}
Copy the code

This class must have appeared as a simple Java class, so it is now clear that the development principles for simple Java classes are:

  1. All attributes encapsulated, already encapsulated;
  2. Generate setter, getter methods;
  3. Construction method, must be parameterless construction
  4. Overrides some methods in Object

shortcuts

In addition to the above generation method can also be generated by shortcut keys

  1. ALT+/ : automatic code replenishment prompt;
  2. CTRL+1: error code correction prompt;
  3. CTRL+D: Delete current line of code;
  4. CTRL+SHIFT+O: Automatic import package;
  5. CTRL+SHIFT+F: Format code display;
  6. CTRL+/ : Comment/Uncomment;
  7. CTRL+ Shift + L: List of shortcuts
  8. CTRL + H: search

Items can also be deleted, but there are two ways to delete items:

Method 1: Delete it from the project workspace and restore it later;

Method 2: Completely delete the project from the hard disk.

If you want to import the project, you can use the import method.

All *.class files in a project can now be exported to automatically generate *.jar files.

The Debug debugging

In Eclipse, in order to facilitate the development of Yonghua, also provides the DEBUG function, you can use this function for project debugging operations, and if you want to DEBUG, first need to set breakpoints. A breakpoint is a point at which the program stops and is then handed over to human control.

** Example: ** Set breakpoints

package com.util;

public class MyMath {
	private MyMath(a){}
	public static int add(int x, int y){
		int temp = 0;
		temp = x + y;
		returntemp; }}Copy the code

The test class

package com.test;

import com.util.MyMath;

public class TestMath {
	public static void main(String[] args) {
		int result = MyMath.add(2.3);// Set this to power off
		System.out.println("Result of addition"+ result); }}Copy the code

After entering the debug attempt, you can debug your code in the following ways:

  1. Jump into the code (F5) : Jump into the code to observe its execution;
  2. Step skipping (F6) : Not concerned with execution in code, only with the end result;
  3. Step back (F7) : Return to step skipped state
  4. Resume execution (F8) : no debugging directly to complete the program.

JUNIT testing tool

Software testing: From 2003 to 2006, companies have been hiring software testers and outsourcing them to IBM or Microsoft. But today’s software testing is a tough business.

Software testing is a golden position, which requires a complete set of testing theory and data design. If you have studied software engineering, you should know that software testing is divided into two categories:

1. Black box testing: mainly testing functions, such as some XX versions, which do not touch the code, but the company will provide tools;

White box testing: refers to performance testing, or algorithm tuning.

In recent years, with the development of the industry, a new test position is actually created — Use Case Test engineer. For this position, the average salary in China is 3-5 times that of programmer. If the normal salary of a programmer is 8000, the average salary of such a person is 20,000-50,000. But people are hard to find, generally speaking, such people need 8-10 years of project experience in the industry, and proficiency in the business.

JUNIT is a more commonly used testing tool, we can Use Case testing, in the future development of the program to write a large number of JUNIT test procedures.

** Example: ** Defines the program to test

package com.util;

public class MyMath {
	private MyMath(a){}
	public static int add(int x, int y){
		int temp = 0;
		temp = x + y;
		returntemp; }}Copy the code

The test class

package com.test;

import static org.junit.Assert.*;

import org.junit.Test;

import com.util.MyMath;

import junit.framework.TestCase;

public class MyMathTest {

	@Test
	public void testAdd(a) {
		TestCase.assertEquals(MyMath.add(2.3), 5); }}Copy the code

When setting up JUNIT tests, there are two forms:

1.JUNIT Test Case: indicates a Test Case, which is used to Test a service.

2.JUNIT Test Case: indicates a group of Test cases, including multiple Test cases.

JUNIT’s test results fall into two categories:

1.GREEM BAR: Passed the test;

2.RED BAR: The test fails.

Basic New Features

The evolution of Java has come a long way since 1995, but there are three most representative JDK versions;

JDK1.0: Marks the birth of Java;

JDK1.2: Added javax. Swing components, which are major new features;

JDK1.5: labeled Tiger, there are many features that are still in use today;

JDK1.8: Lambda expressions and interface definitions are enhanced

I’ve seen some new features, such as automatic boxing and unboxing, and Switch support for String judgment.

Variable parameter

Before we get to mutable parameters, let’s consider a question: If we wanted to add a number of integer variables, how would we design this method? Use array to receive, because the number of parameters is uncertain, according to the previous learning, can only use array to complete.

package com.demo;

/ * * *@authorShengrui Zhang * */
public class TestDemo {
	public static void main(String[] args) {
		System.out.println(add(new int[] {1}));
		System.out.println(add(new int[] {1.2.3}));
		System.out.println(add(new int[] {1.2.3.4.5.6.7}));
	}
	
 /** * implement any number of data add operation processing *@paramData adds data *@returnReturns the sum of multiple data */
public static int add(int [] data){
		int sum = 0;
		for (int i = 0; i < data.length; i++) {
			sum += data[i];
		}
		returnsum; }}Copy the code

The above does fulfill the technical requirements, but now there is a new problem: if according to the requirements of the title, it should be possible to pass more than one data, but the above data is actually uploaded in the form of an array encapsulation. To better solve this problem, we can use JDK1.5’s mutable parameters to solve this problem

Public [static]  [final] Return value type method name (parameter type... Variable) {// Although the way has changed
    [return[return value]; ] }Copy the code

I noticed that the method parameters are now defined in a different way, and the parameters are in array form.

package com.demo;

/ * * *@authorShengrui Zhang * */
public class TestDemo {
	public static void main(String[] args) {
		System.out.println(add(1));
		System.out.println(add(1.2.3));
		System.out.println(add(1.2.3.4.5.6.7));
	}
	
 /** * implement any number of data add operation processing *@paramData adds data *@returnReturns the sum of multiple data */
public static int add(int. data){
		int sum = 0;
		for (int i = 0; i < data.length; i++) {
			sum += data[i];
		}
		returnsum; }}Copy the code

With variable parameters in the process of method call in the future, it can be more intuitive to pass any number of parameters, but the operation of exception is not recommended in development, it is best not to use.

The foreach output

Foreach is not a new concept, it was first proposed in NET. Foreach can be understood as an enhanced for loop. Here is a review of the earliest for loops:

package com.demo;

/ * * *@authorShengrui Zhang * */
public class TestDemo {
	public static void main(String[] args) {
		System.out.println(add(1));
		System.out.println(add(1.2.3));
		System.out.println(add(1.2.3.4.5.6.7));
		
		
	}
	
 /** * implement any number of data add operation processing *@paramData adds data *@returnReturns the sum of multiple data */
public static int add(int. data){// Receive the original array
		int sum = 0;
		for (int i : data) {	// Set each element in the array to x
			sum += i;// This loop avoids the footer problem
		}
		returnsum; }}Copy the code

But with foreach, there is new support for arrays or collections. The syntax is as follows:

for(array data type variables: | collection) {// Operation code
}
Copy the code

This for loop avoids the problem of arrays being out of bounds, but it still requires that you can use it and understand it, but my personal advice is: don’t use it.

Static imports

If you want to import the methods of a class in a different package, you must use import to do so: here is the format used previously.

Define a MyMath class

package com.util;

public class MyMath {
	private MyMath(a){}
	public static int add(int x, int y){
		int temp = 0;
		temp = x + y;
		return temp;
	}
	public static int sub(int x,int y){
		return x-y;
	}
	public static int mul(int x,int y){
		return x*y;
	}
	public static int div(int x,int y){
		returnx/y; }}Copy the code

In JDK1.5 value week, if all methods in a ray are static, you can import them using the following syntax:

import staticPackage. Class.*;Copy the code

Means to import all the methods in the specified class as if they were all defined in the main class.

package com.test;

import static com.util.MyMath.*;// Static import

public class TestMath {
	public static void main(String[] args) {
		System.out.println(add(10.20));
		System.out.println(sub(30.10)); }}Copy the code

This kind of uncomfortable method, also only appears in the lecture, I will never use, you can forget it.