SlideShare una empresa de Scribd logo
1 de 14
ITStudent.net – Trong bài viết thiết lập môi trường lập
trình Java mà chúng tôi đã giới thiệu trước đây, chúng ta
đã biết được những thành phần cài đặt cần thiết và cách
tạo lập môi trường để lập trình Java trong Windows.
Tiếp theo, trong bài viết lần này chúng ta sẽ làm quen với
việc tạo project và viết một chương trình cơ bản bằng
java sử dụng IDE Eclipse.
I. Tạo một project bằng Eclipse
Bước 1: Khởi động Eclipse để vào màn hình làm việc chính của Eclipse
Bước 2: Vào menu File chọn New và Project….
Eclipse sẽ hiển thị cửa sổ tuỳ chọn New Project sau đây:
Chọn Java Project rồi nhấn Next (hoặc double click vào Java Project) sẽ xuất hiện cữa sổ New
Java Project như sau:
Tại mục Project name: nhập tên project cần tạo vào và nhấn nút Finish, Eclipse sẽ đưa ta đến
màn hình làm việc cùng với project vừa tạo
II. Tạo một chương trình java cơ bản
Bước 1: Tạo gói (Java Package)
Gói trong lập trình Java là một nhóm các lớp và giao tiếp có quan hệ với nhau được tổ chức
như một đơn vị không gian tên.
Gói giúp phân hoạch không gian tên lớp, giao diện thành những vùng dễ quản lý hơn
Để tạo mới 1 gói trong Eclipse, chúng ta cần click phải vào project rồi chọn New Package
Eclipse sẽ yêu cầu chúng ta chỉ định các thông số cần thiết cho 1 package cần tạo qua cửa sổ sau:
Tại mục
Name: nhập tên của gói
Tên gói có một số quy định sau:
Tên gói phải là chữ thường
Tên gói không được bắt đầu bằng java hoặc javax
Không được bắt đầu bằng số hoặc dấu nối (-)
Sau khi nhập tên gói xong thì chọn Finish ta được:
Bước 2: Tạo lớp (Java Class)
Trong lập trình Java, lớp (java class) là nơi chứa một tập hợp các đối tượng, constructor, phương
thức, hàm, …. mà ta thực thi lên đó.
Để tạo lớp, chúng ta sẽ click phải vào tên gói và chọn New Class
Cửa sổ sau sẽ xuất hiện yêu cầu nhập tên Class vào mục Name:
Tên class có một số quy định như sau:
Viết hoa chữ cái đầu tiên của mỗi từ
Không bắt đầu bằng một số, phải bắt đầu bằng ký tự hoặc $, _
Không chứa dấu cách hoặc các ký tự toán học: *,/, %,….
Không trùng với tên khác trong cùng gói (tên lớp phân biệt chữ hoa và chữ thường).
Sau khi đặt tên lớp xong chọn Finish ta sẽ có:
Bước 3: Tạo chương trình cơ bản
Để chạy được chương trình thì ta cần phải có hàm main() như sau:
1
2
3
4
publicclassHelloJava {
publicstaticvoidmain(String[] args) {
}
}
Để in ra kết quả thì ta cần hàm println() như sau:
1
2
3
publicstaticvoidmain(String[] args) {
System.out.println();
}
Ví dụ: nếu muốn in ra chữ “ITStuden.net” ta viết như sau:
1
2
3
publicstaticvoidmain(String[] args) {
System.out.println("ITStudent.net");
}
Có nhiều cách để có thể chạy một chương trình Java được viết trong Eclipse:
Cách 1: Click vào nút Run trên thanh công cụ
Cách 2: click phải vào lớp chọn Run As và Java Application
Cách 3: nhấn tổ hợp phím Ctrl + F11
Sau khi chạy kết quả sẽ thu được là:
Như vậy, chúng ta đã làm quen với việc tạo một project và viết một chương trình java cơ
bản bằng Eclipse IDE
It student làm quen với eclipse trong lập trình java

Más contenido relacionado

Destacado

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

It student làm quen với eclipse trong lập trình java

  • 1. ITStudent.net – Trong bài viết thiết lập môi trường lập trình Java mà chúng tôi đã giới thiệu trước đây, chúng ta đã biết được những thành phần cài đặt cần thiết và cách tạo lập môi trường để lập trình Java trong Windows. Tiếp theo, trong bài viết lần này chúng ta sẽ làm quen với việc tạo project và viết một chương trình cơ bản bằng java sử dụng IDE Eclipse. I. Tạo một project bằng Eclipse Bước 1: Khởi động Eclipse để vào màn hình làm việc chính của Eclipse Bước 2: Vào menu File chọn New và Project….
  • 2. Eclipse sẽ hiển thị cửa sổ tuỳ chọn New Project sau đây:
  • 3. Chọn Java Project rồi nhấn Next (hoặc double click vào Java Project) sẽ xuất hiện cữa sổ New Java Project như sau:
  • 4. Tại mục Project name: nhập tên project cần tạo vào và nhấn nút Finish, Eclipse sẽ đưa ta đến màn hình làm việc cùng với project vừa tạo
  • 5. II. Tạo một chương trình java cơ bản Bước 1: Tạo gói (Java Package) Gói trong lập trình Java là một nhóm các lớp và giao tiếp có quan hệ với nhau được tổ chức như một đơn vị không gian tên. Gói giúp phân hoạch không gian tên lớp, giao diện thành những vùng dễ quản lý hơn Để tạo mới 1 gói trong Eclipse, chúng ta cần click phải vào project rồi chọn New Package
  • 6. Eclipse sẽ yêu cầu chúng ta chỉ định các thông số cần thiết cho 1 package cần tạo qua cửa sổ sau:
  • 7. Tại mục Name: nhập tên của gói Tên gói có một số quy định sau: Tên gói phải là chữ thường Tên gói không được bắt đầu bằng java hoặc javax Không được bắt đầu bằng số hoặc dấu nối (-) Sau khi nhập tên gói xong thì chọn Finish ta được:
  • 8. Bước 2: Tạo lớp (Java Class) Trong lập trình Java, lớp (java class) là nơi chứa một tập hợp các đối tượng, constructor, phương thức, hàm, …. mà ta thực thi lên đó. Để tạo lớp, chúng ta sẽ click phải vào tên gói và chọn New Class
  • 9. Cửa sổ sau sẽ xuất hiện yêu cầu nhập tên Class vào mục Name:
  • 10. Tên class có một số quy định như sau: Viết hoa chữ cái đầu tiên của mỗi từ Không bắt đầu bằng một số, phải bắt đầu bằng ký tự hoặc $, _ Không chứa dấu cách hoặc các ký tự toán học: *,/, %,…. Không trùng với tên khác trong cùng gói (tên lớp phân biệt chữ hoa và chữ thường). Sau khi đặt tên lớp xong chọn Finish ta sẽ có:
  • 11. Bước 3: Tạo chương trình cơ bản Để chạy được chương trình thì ta cần phải có hàm main() như sau: 1 2 3 4 publicclassHelloJava { publicstaticvoidmain(String[] args) { } } Để in ra kết quả thì ta cần hàm println() như sau: 1 2 3 publicstaticvoidmain(String[] args) { System.out.println(); } Ví dụ: nếu muốn in ra chữ “ITStuden.net” ta viết như sau:
  • 12. 1 2 3 publicstaticvoidmain(String[] args) { System.out.println("ITStudent.net"); } Có nhiều cách để có thể chạy một chương trình Java được viết trong Eclipse: Cách 1: Click vào nút Run trên thanh công cụ Cách 2: click phải vào lớp chọn Run As và Java Application
  • 13. Cách 3: nhấn tổ hợp phím Ctrl + F11 Sau khi chạy kết quả sẽ thu được là: Như vậy, chúng ta đã làm quen với việc tạo một project và viết một chương trình java cơ bản bằng Eclipse IDE