Computers Windows Internet

Java programming basics for beginners. Java Programming for Beginners

Do you want to learn how to program? Sound thought: such a skill, most likely, will not be superfluous. True, this will require a little work. This is a cycle of classes that will allow you, in the foreseeable future, not only to get an idea of ​​what programming is, but also to learn how to create programs of non-trivial purpose and size.

It is also important to understand that the conversation should be mutually exclusive. Quite often people come to a conversation expecting an answer to the questions asked. However, if your employer doesn't ask you about your specific skills, and you don't tell yourself about it, that would be your mistake. Employers are looking for people who want to learn, with strong motivation to grow and achieve results.

Admittedly, some of the students himself is one of the most difficult, so if you manage to get an invitation for an interview, then, a significant bargaining chip in hand. Employers themselves know very well that learning to work in another field or staying at a university is very difficult and valuable.

There are several ways to teach programming.

The first and, perhaps, the most common one is from books. All you need to do is find a suitable book and sequentially, page by page, read it and complete all the proposed exercises (if any). If the book is worthwhile (preferably from the authors of a technology or programming language), then sooner or later, this method will give excellent results: you will know and understand most of necessary material... But this method is long and not very suitable for those who are just starting to program and whose experience is limited to the most primitive information that he or she received at school or at work. You need to have a fair amount of patience, perseverance (often even stubbornness) to "wade" through a lot of new concepts, concepts and unusual terminology. Still, books are good for those who have at least basic knowledge of the subject and do not stop at every line just to simply understand what is at stake.

Don't be afraid to ask if you are working. Making a successful transition to negotiating work and tasks is a challenge to work. Naturally, workspace, tasks and projects will be very different from what you did at home. It looks daunting at first, but you don't need to be afraid.

First, you will see that your team or colleagues may work in a different way than you are used to or work. In such cases, he should be relatively flexible and should not strictly adhere to his own procedures. Another problem we notice is that self-taught colleagues are often afraid to ask questions when there is uncertainty. The employee and employer must understand that there are no stupid questions and do not ask, and not lose, unlike many. Only in this way the employer will understand what knowledge you lack, and you - how to work effectively and not stop improving.

In addition, without experience, you are unlikely to choose exactly the book that will provide the necessary knowledge. The book market is littered with high-quality waste paper. But the value of most of these manuals, textbooks and books is more than questionable. Sometimes a small and nondescript book at a ridiculous price turns out to be immeasurably more useful than a luxurious edition with excellent graphics on coated paper (and a price ten to fifteen times more).

In addition, many employers are willing to help as many newbies as possible. For example, we are very proud that all newbies are required to travel for 2-6 weeks. in which both stronger and less weak competencies are observed, and at the same time we organize an individual development plan for the employee, which is accelerated as quickly as possible and purposefully improved.

The market is very dynamic and constantly changing. New technologies, libraries and tools are constantly being updated, so the developer's work is in full swing. It doesn't matter if you are a junior or a senior - everyone has to learn. It's also noticeable in work conversations - programmers don't motivate fruits or games, they need good environmental improvements.

In addition, many employers are willing to help as many newbies as possible. For example, we are very proud that all newbies are required to travel for 2-6 weeks. in which both stronger and less weak competencies are observed, and at the same time we organize an individual development plan for the employee, which is accelerated as quickly as possible and purposefully improved.

The second way is courses with an experienced teacher. The ideal option is when you and the teacher work in pairs: the teacher - explains and shows, you - try to repeat and develop. You can stop at any time and clarify what you do not understand. The teacher himself can adjust the pace of learning in accordance with your successes or failures. It is somewhat worse when there is only one teacher and several students. Usually this method also gives excellent results, provided that the group is not very large (say, 3, maximum 5 people) and the level of preparation of all students is approximately the same. If there is an opportunity and finances allow paying for such courses, it is better to use them.

Unfortunately, this method is not available to residents of small settlements where there are no training centers, as well as to those whose income level is not high enough to afford such a “luxury”. Of course, it happens that the employer at his own expense sends his employees to training courses, but then someone is as lucky.

The third way (and right off the bat - the best of all) is to work alongside an experienced mentor. Books - by books, courses - by courses, and personal example, especially in real ("combat") conditions, is just a godsend. Sometimes it’s enough to just sit and observe, asking questions as needed. If the mentor is a sane person (and real professionals, as a rule, sane and benevolent people), then in a few weeks you will get something that will allow you to start working on tasks of average complexity and not go to reference books every minute in search of elementary things. During such a period, you, of course, will not become a professional, but you will not be a complete beginner either. Of course, in the learning process, you need to remember about a sense of proportion and not "bother" a busy specialist with very elementary questions: first you need to look for the answer yourself. So you will get the necessary knowledge and skills practically free of charge and in a very short time.

But what if this method is not feasible, but you want to learn? Is it really possible to take a chance and turn to books? Still, the situation is not hopeless. We decided to prepare a small training course for beginners. This course contains only the essentials, but provides a sufficient understanding of the subject and skills that will allow you to move on on your own. Of course, the absence feedback there will be a known obstacle between you and us, but we hope that with some effort you will be able to learn a thing or two. In any case, we hope that after studying this course in full, you will be able to move on on your own. Of course, we do not promise you an easy life, but we will try to help. Before moving on to the actual course itself, read and think about a few recommendations:

  • Information Technology you can, of course, study without a computer, but you must admit that with a computer it is still more comfortable and more practical; therefore a computer is necessary. Any model no older than 5 years will do. There are no special requirements for the filling and hardware configuration, but remember these simple rules - the more RAM, the better, the better the monitor, the more convenient it is. In short, don't skimp on trifles, but don't waste your money either. A typical laptop that costs about $ 500 or more is just fine.
  • any modern operating system must be installed on the computer (which is absolutely not important): Windows, Linux, MacOS, FreeBSD, etc. Since the overwhelming majority of users have an operating system of the Windows family (of one version or another) from Microsoft on their computers, in what follows we will focus primarily on it. You must be able to work on a computer (use a keyboard, mouse, USB devices, a printer, connect to the Internet, etc.). Skills of working with text editors or spreadsheets. In general, remember that the main tool of the programmer (after the head, of course) is the keyboard, so if you can hardly find the space bar on the keyboard, then you will have big problems... Only practice can help here.
  • as for the required for this course software, we will talk about it next time. Let's just note that you need an Internet connection to get it. If you are reading these lines, then you already have such a solution.
  • the course is designed for regular work. Resist the temptation to skip over what seems elementary to you and jump to next topic: this is fraught with unpleasant consequences, tk. you may miss a subtle point or an important detail.
  • information technologies are oversaturated with specific terminology, mainly of English-speaking origin; almost all valuable documentation is written in English language... So it is useful to arm yourself with at least some kind of dictionary (any electronic one will do and not even the most powerful one) - gradually you will get used to and learn most of the necessary phrases and terms.
  • the duration of each lesson is from 15 to 40 minutes. Each lesson should be studied completely: from cover to cover. We tried to make the course as clear as possible, but without water and lengthy arguments. Examples of program code must be typed and tested on your computer (this, however, is not always feasible if a large issue is being considered and the discussion is stretched over several sessions, but sooner or later you must - even must - get the result as it should be).
  • if you are tired - take a day off, then another. No catastrophe will happen. But not more. Do not try to make up in a day what you had to learn for two months - you will get tired, confused and, in the end, disappointed in yourself or in what you were doing. If there is a break, then don't rush to catch up. The main thing is not to remember, but to understand. What is understood is remembered by itself. So no cramming.
  • start a notebook or notebook and mark in it what you think is important. No need to take notes - just write down what you - specifically you - thought interesting, stupid, funny. It can be a phrase, a piece of code, a quote, a caricature - whatever. Review earlier entries periodically; it will help you remember what you have learned.

Our approach is closest to the third way of learning - i.e. learning with a mentor. Our principle is simple: show and explain key details. We will not take a long, boring and tedious discussion of simple and obvious things (about them, if necessary, you will find enough information in books, documentation, and specialized forums). We will gradually develop a small application that will show you the work of a professional programmer. But "small" does not mean "simple" - not at all! You will have to work hard to get the result. But do not be afraid - the result is worth it. The main thing is to want and follow the set goal, overcoming hills and holes along the way.

Now, let's take a break. Prepare your computer for the next lesson — make sure your hard disk has at least 1 GB of free disk space; if the RAM is less than 1GB, then find out if it can be increased and be sure to increase it (with RAM do not save at all: if the computer allows you to install 4 GB, then install that much; Believe me, it pays off with the comfort of work and time saving): we have a little tedious, but necessary work to install multiple programs. So see you soon!

Barry Bird "Java for Dummies" Williams, 2013, 5th edition, 363 pp. (8.23 MB djvu)

About Java.

For dummies, it's like programming. It sounds trite, but Java is by far the most popular programming language. It is used for programming more than C ++ and C # combined. Start learning Java if you want to learn programming and you won't go wrong. The code written in this programming language is cross-platform. It will run on any device and under the control of any operating system where the Java virtual machine (JRE) is installed - "Wrote once, works everywhere." The book "Java for Dummies" is designed for them.

About the book.

If you have never studied programming and do not know about OOP, do not be discouraged, Barry Bird is good at explaining. At a minimum, the basic concepts of object-oriented programming and basic knowledge of the Java language are guaranteed to you. Subject to a careful study of the material in the book and the completion of assignments in the form of code examples. In the guide, the author will talk about the history of the Java language, its main concepts, advantages and disadvantages, existing versions and their differences, the tools required for coding and execution ready-made programs(JDK, JRE, Eclipse).

Learn the basics: grammars (syntax) of the language, the concept of API classes (standard libraries), write your first program. For the initial stage learning Java this book is enough. If you have the courage to finish reading it and complete at least some of the assignments, then you can start studying more voluminous and. The path to perfection has a beginning but no end.

Table of contents of the book
About the author 13
Introduction 15
How to work with this book 15
Conventions Used in Book 15
What you can not read 16
Several Assumptions 17
Structure of Book 18
Part I. Java Basics 18
Part II. Writing a Java 18 Program
Part III. Object Oriented Programming 18
Part IV. Programming Best Practices 19
Part V. Magnificent Tens 19
Part VI. Appendices 19
Pictograms Used in Book 19
What's next 20
Looking forward to your feedback! twenty

Part I. Java Basics 21

Chapter 1. Familiarity with Java 23
What can be done with Java 24
Why write programs 25
A bit of history 25
Object Oriented Programming 28
Object Oriented Languages ​​28
Objects and Classes 30
Benefits of an Object Oriented Approach 31
Visualizing Classes and Objects 32
What's next 33

Chapter 2. Software development 35
Quick Start 35
What should be installed on the computer 37
What is a compiler 38
What is Java Virtual Machine 40
Development process 45
Integrated Development Environment 46

Chapter 3. Basic Java Components 49
Let's talk on Java language 49
Grammar and Common Names 50
Words in a Java Program 51
Your first Java program 53
How Your First Program Works 54
Classes 54
Methods 55
The main method of the program 57
How to tell a computer to do a desired operation 58
Curly braces 60
Don't say "No comment ..." 62
Adding Comments to Code 63
Don't be too hard on old Barry 66
Using Comments to Experiment with Code 66

Part II. Writing a Java Program 69

Chapter 4. Variables and Values 71
Volatile variable 71
Assignment Operator 74
Types of values ​​and variables 75
Displaying Text 77
Numbers without decimal point 78
Initialization on declaration 79
Java 80 primitive types
Char type 81
Boolean 82 type
Reference types 83
Import Declaration 86
Creating New Values ​​with Operators 87
You can initialize once, but you can assign many times 89
Increment and Decrement Operators 89
Assignment Operators 93

Chapter 5. Control instructions 95
Deciding with an if Statement 95
Guess the number 96
Entering Text Using the Keyboard 96
Generation random numbers 98
If statement 98
Double equal sign 100
Blocks 100
Indentation in if statement 101
Broken fork (if no else) 101
Conditions with Comparison Operators and Boolean Operators 102
Comparison of numbers and symbols 102
Comparison of objects 103
Importing Everything in One Time 105
Logical operators 106
How “zero” differs from “nothing” 108
Conditions in brackets and parentheses in conditions 109
Nesting if statements 111
Switch 113
Option selection 113
Don't forget to insert break! 115
String argument - new in Java 7 117

Chapter 6. Cycles 119
While loop 119
Loop for 122
The structure of the for loop
Premiere of the hit "Al in the Rain" 125
Cycle do 126
Reading one character from the keyboard 129
File Manipulation 130
Variable declaration in block 130

Part III. Object Oriented Programming 131

Chapter 7. Classes and objects 133
Class definition 133
Open class 135
Declaring Variables and Creating Objects 135
Variable initialization 138
One program is many classes 139
Defining a Method in a Class 139
Self-Representing Account 140
Method header 141
Passing Parameters to a Method and Getting a Value from a Method 142
Passing a value to method 144
Method Returned Value 145
How to Make Numbers Look Nice 147
Access modifiers 151
Correct Programming Style 152
Making a Field Inaccessible 154
Checking Rules Using Access Methods 156

Chapter 8. Code reuse 157
Class definition 158
Class Identifying Employee 158
Correct use of class 159
Create a payment check 161
Working with files (a small digression) 162
Storing data in a file 162
Copying and pasting code 163
Reading from a file 164
Where did my file go? 166
Adding Folder Names to File Name 166
Line by line reading 167
Inheritance 169
Derived Class 171
Using Derived Classes 174
Conformity of types 175
Using the PartTimeEmployee Class 176
Overriding Existing Methods 177
Annotations 179
Calling Base and Derived Methods 179

Chapter 9. Constructors 181
Defining a Constructor 181
What is temperature 182
What is temperature scale 182
So what is temperature? 183
What can be done with a temperature of 185
Finding the Right Constructor 186
Some Things Never Change 189
Base Class Constructor in Derived Class 190
Improved temperature class 190
Derived Class Constructors 191
Using advanced temperature class 192
Default constructor 193
A constructor can do more than fill in 194 fields
Classes and Java methods AP 196
Annotation @SuppressWarnings 198

Part IV. Advanced programming techniques 199

Chapter 10. Correct use of variables and methods 201
Class definition 201
Another Way to Make Numbers Beautiful 202
Using the Player 203 class
Nine Constructor Calls 205
Graphical User Interface 205
Kick the Exception to Another Method 207
Static Fields and Methods 207
Why so much static 209
Static Initialization 210
Display of general statistics of the command 210
Static imports 212
Caution, static! 213
Experimenting with Variables 214
Variable in place 215
Variables in different places 217
Passing Parameters 219
Pass by Value 219
Returning result 221
Transfer by reference 221
Returning an Object from Method 223
Epilogue 224

Chapter 11. Arrays and Collections 225
How to arrange items in a row 225
Creating an Array in Two Steps 227
Storing values ​​228
Tabulostops and others Special symbols 230
Array Initialization 230
Extended for loop 231
Search 233
Arrays of Objects 236
Using Room 237
Another way to decorate numbers 240
Ternary conditional operator 241
Arguments command line 241
Using command line arguments in Code 242
Checking the Number of Command Line Arguments 244
Collections 245
Collection Classes 246
ArrayList Class 247
Using generic types 250
Checking if there is more data 250

Chapter 12. How to keep a good face on a bad game 253
Exception Handling 254
Catch block parameter 258
Types of Exceptions 259
Who Should Catch Exception 261
A catch block with multiple types of exceptions 267
Let's not be overly cautious 267
Restoring the program after an exception 268
Our Friends Are Good Exceptions 269
Handle the exception or pass it on 270
Finally block 274
Closing Files 276
How to close file 276
Resources in the header of a try block 276

Chapter 13. Area of ​​visibility 279
Access Modifiers to Class Members 280
Classes, Access, and Program Parts 280
Classes and Class Members 281
Class Member Access Rules 281
Example with picture in frame 283
Folder structure 285
Frame Creation 286
How to Change a Program Without Changing Classes 287
Default access 289
How to break into package 292
Protected Access 292
Including a Non Derived Class in the Same Package 294
Class Access Modifiers 295
Open classes 296
Not open classes 296

Chapter 14. Responding to keyboard and mouse events 299
Mouse Click Response 299
Events and Event Handling 301
Java Interfaces 302
Threads 303
This 304 keyword
The body of the actionPerf ormed () method 305
Version ID 305
Responding to other events 306
Indoor Classes 311

Chapter 15. Applets 315
Example of a simple applet 315
Executing applet 316
Open class 317
Java API Classes 317
Animated applet 318
Methods used in the applet 319
Content of Applet Methods 320
Reacting to events in an applet

Stava 16. Database connection 325
JDBC and Java DB 325
Creating Database Records 326
Using SQL 328 Commands
Attaching and Detaching a Database 328
Data Extraction 330

Part V. Magnificent tens 333

Hpava 17. Ten Ways to Avoid Mistakes 335
Correct use of case of letters 335
Exit from block switch 336
Comparing Two Values ​​336
Adding an Element to the GUI 336
Adding Event Receivers 337
Defining Constructors 337
Fixing non-static links 337
Respecting Array Boundaries 337
Pointers to nu 11 338
Help virtual machine Java find classes 338

Chapter 18. Ten Java Sites 341
The Websites for This Book 341
Java Sites 341
News, reviews, example codes 342
Job 342
Websites for everyone 342

Part VI. Applications 343

Appendix A. Installing an Integrated Development Environment 345
Download and Install JDK 345
Downloading and Installing Eclipse 349
Configuring Eclipse 351
Appendix B. Using Eclipse 353
Working with Book Examples 353
Creating your own project 355
Index 359

Download the book for free 8.23 ​​MB. djvu

Java for dummies. Video