The book "Programming Basics with Java" introduces the readers with writing programming code at a beginners level (basic coding skills), working with development environment (IDE), using variables and data, operators and expressions, working with the console (reading input data and printing output), using conditional statements (if
, if-else
, switch-case
), loops (for
, while
, do-while
, foreach
) and methods (declaring and calling methods, passing parameters, and returning values). This book teaches basic coding skills, using the programming language Java and the development environment IntelliJ IDEA. The learning material covered in this book delivers the basic training that is needed for further more in-depth study of programming and prepares the reader for the entrance exam at SoftUni.
This book only gives you the first steps to programming. It covers very basic skills that you must develop for years, in order to reach a high enough level and start working as a programmer. |
The book is used as unofficial textbook for school-level programming courses in the high schools, studying professions like "Programmer", "Application Programmer" and "System Programmer", as well as an additional teaching tool in the initial programming courses at the secondary schools, mathematical and professional high schools.
That book is suitable for absolute beginners in programming who want to try what programming is and learn the main constructions for writing programming code that are used in software development, regardless of the programming language and the technologies used. The book gives a solid basis of practical skills that you can use in any future training in programming and software development.
For anyone who hadn't passed the free course on Programming Basics in SoftUni, we specifically recommend to sign up for it completely free, because one learns programming by doing it, not by reading it! During the course you will get free access to lessons, explanations and demonstrations on site or online (such as video tutorials), a lot of practice and code writing, help with the task solutions after each topic, access to trainers, assistants and mentors, as well as forums and discussion groups for any questions, access to a community of thousands of people who are new in programming, and any other help that a beginner might need.
The free course for beginners in SoftUni is suitable for school students (of age 10+), university students and workers having any other professions, who want to gain technical knowledge and check if programming is what they like to do and understand if they would like to develop in the software development field.
A new group starts each month. The "Programming Basics" course at SoftUni is organized regularly using a few different programming languages as basis. So, just check it out! The course is free, and you can quit any time you like. Signing up for free on-site or online training is available via the SoftUni application form: https://softuni.org.
For this book, we choose the Java because it is a modern programming language for high-level programming, open source, easy to learn and suitable for beginners. Using Java is widespread, with a well-developed ecosystem, numerous libraries and technology frameworks, and accordingly, it gives many perspectives for development. Java combines paradigms of procedural, object-oriented and functional programming in a modern way with easy syntax although it is more descriptive than Python and JavaScript. In this book, we will use Java language and IntelliJ IDEA development environment, which are available for free.
As we will explain later, the programming language that we start with, does not make a significant difference, but we still need to use some programming language, and in this book we choose Java specifically. The book can also be found mirrored in other programming languages such as C# and JavaScript (see https://java-book.softuni.org).
This book on programming for beginners is available in several programming languages (or is in the process of being adapted for them):
- Programming Basics with C# (Bulgarian)
- Programming Basics with C# (English)
- Programming Basics with Java (Bulgarian)
- Programming Basics with JavaScript (Bulgarian)
- Programming Basics with Python (Bulgarian)
- Programming Basics with C++ (Bulgarian)
If you prefer a different language, select it from the list above.
If someone thinks they will read a book and learn to program without writing code and solving problems, this is definitely a delusion. Programming needs a lot of practice, with code writing every day and solving hundreds, even thousands of problems, seriously and persistently for years.
You need to solve a lot of problems, to make mistakes, to fix, to search for solutions and information from the Internet, to try, to experiment, to find better solutions, to get used to the code, syntax, the programming language, the development environment, to search for errors and debugging the broken code, the algorithmic thinking, breaking the problems into smaller parts, gaining experience and raising your skills every day, because when you learn to write code, this is only the first step to the profession of the "software engineer". You have a lot to learn, really!
We advise the reader, as a minimum, to try out all the examples from the book, to play with them, to change them and test them. Even more important than the examples are the exercises because they develop the programmer's practical skills. This book provides nearly 150 practical coding exercises, so it is a good foundation for developing coding and algorithmic thinking skills.
You need to solve all the problems in the book because programming is learned with practice! The exercises after each topic are carefully selected to cover in depth the learning material. The purpose of solving all the problems is to provide complete set of skills for writing programming code at a beginners level (which is the purpose of this book). During the courses in SoftUni we purposefully focus on practice and problem solving, and in most courses code writing occupies over 70% of the entire course.
Solve all the exercises in the book. Otherwise you won't learn anything! Programming is learned by writing a lot of code and solving thousands of problems! |
The Software University (SoftUni) is the largest training center for software engineers in the South-Eastern Europe. Tens of thousands of students pass through the university every year. SoftUni was founded in 2014, as a continuation of the hard work of Dr. Svetlin Nakov in training skillful software engineering professionals by a practical, contemporary and high-quality education, that combines fundamental knowledge with modern software technologies and a lot of practice.
The Software University provides quality education, profession, job and diploma for programmers, software engineers and IT professionals. SoftUni builds an extremely successful and strong connection between education and industry by collaboration with hundreds of software companies, provides job and internship of its students, creates quality professionals for the software industry and directly responds to the needs of employers via the training process.
SoftUni organizes free programming courses for beginners: online and physically in few locations. The purpose is to give a chance to everyone who is interested in programming and technologies to try programming and check if they are interested and if they would get seriously involved in software development. You can sign up for the free course in programming basics using the SoftUni application page: https://softuni.org.
The free programming basics courses at SoftUni have the purpose to introduce you to basic programming constructions in the software development world, that you can use in any programming language. These include working with data, variables and expressions, using conditional statements, constructing loops, defining and calling methods and other approaches for building programming logic. The trainings are highly practically oriented which means that the emphasis is strongly on exercises, and you get the opportunity to apply your knowledge during the learning process.
This programming book accompanies the free programming lessons for beginners at SoftUni and serves as an additional teaching aid to help the learning process.
The SoftUni Judge system (https://judge.softuni.org) is an automated Internet system for checking the solutions of programming exercises via series of tests. The submission and verification happen in real time: you submit the solution and within seconds you get an answer whether it is correct. Each successfully taken test gives you the points it gains. For a completely correct solution you get all the points for this problem. For partially correct solution you get part of the points for the task. For a completely wrong solution you get 0 points.
This how the SoftUni Judge looks like:
All problems from the current book are available for testing in SoftUni judge and we strongly recommend testing them after you solve them to be sure you don't miss anything and that your solution works correctly according to the task requirements.
Keep in mind some specifics about SoftUni judge:
- For each task the judge system keeps the best score you had. Therefore, if you upload a solution with wrong code or lower score compared to the previous one, the system won't take away your points.
- The output of your program is compared by the system to a strictly expected result. Every unnecessary symbol, missing comma or space may lead to 0 points on a particular test. The output that the judge expects is described in the requirements of every task and nothing else should be added.
Example: If the output requires to print a number (e.g. 25
), do not display any descriptive messages such as The result is: 25
, just print as it is required, i.e. only the number.
The SoftUni judge system is available any time via its website: https://judge.softuni.org.
- To sign in use your authentication for the SoftUni website: https://softuni.org.
- Using the SoftUni system is free and it's not bound with the participation in SoftUni's courses.
We are convinced that after sending a few tasks you will like getting instant feedback for your solutions and the Judge system will become your favorite assistant in your programming practice.
Dear readers, probably many of you have the ambition to become programmers and develop software for a living, or work in the IT area. That's why we have prepared for you a short guide on "How to become a programmer", so we can help you take the first steps towards this desired profession.
You can become a programmer (working in a software company) after at least 1-2 years of intensive training and coding every day, solving thousands of programming tasks, development of several more serious practical projects and gaining a lot of experience with code writing and software development. You can't become a programmer for a month or two! The profession of software engineer requires a lot of knowledge, covered with a lot of practice.
There are 4 main skill groups where all programmers must have. Most of these skills are resistant in time and are not influenced by the development in specific technologies (that are changing constantly). These are the skills that any good programmer has and to which every beginner must strive:
- **coding **(20%)
- algorithmic thinking (30%)
- computer science and software engineering concepts (25%)
- languages and software technologies (25%)
Writing code forms around 20% of the minimum knowledge and skills of a programmer, needed for starting a job in a software company. The skill of coding includes the following components:
- Working with variables, conditional statements, loops
- Using functions, methods, classes and objects
- Data manipulation: arrays, lists, hash tables, strings
The skill of coding can be acquired in a few months of hard learning and solving practical problems by writing code every day. This book covers only the first point of coding: working with variables, conditional statements and loops. The rest remains to be learned in follow-up trainings, courses and books.
The book (and the courses based on it) gives only the beginning of one long and serious training on the way to professional programming. If you don't learn perfectly the material from this book, you can't become a programmer. You are going to miss fundamentals and it will be harder in the future. For this reason, give enough time to programming basics: solve many problems and write code every day for months until you learn to solve every problem from the book very easily. Then go ahead.
We pay special attention to the fact that programming language doesn't have significant relevance for one's coding skill. You can either code or not. If you can code in C#, then you'll easily switch to Java, or C++, or any other language. That's why coding skills are heavily studied in the foundational software engineering courses at SoftUni. These are the skills that each programming book for beginners starts with, including this one.
The algorithmic (logical, engineering, mathematical, abstract) thinking forms around 30% of the minimum skills of a programmer needed to start the profession. Algorithmic thinking is the ability to break a particular problem into a logical sequence (algorithm), to find a solution for every separate step and then assemble the steps into a working solution. That is the most important skill of any programmer.
How to build algorithmic thinking?
- Algorithmic thinking is developed by solving multiple programming (1000+) problems, as diverse as possible. That is the recipe: solving thousands of practical problems, building algorithms and implementing the algorithms, along with debugging the issues that come up in the process.
- Sciences like physics, mathematics and identical ones helps a lot, but they are not mandatory! People with engineering and technical skills usually learn very easily to think logically, because they already have problem solving skills, even if it is not algorithmic.
- The ability of solving programming problems (for which algorithmic thinking is needed) is extremely important for a programmer. Many companies test particularly this skill during their job interviews.
The current book develops the beginner level of algorithmic thinking, but it's not enough to make you a good programmer. To become good at this profession you must add logical thinking and problem solving skills, beyond the range of this book. For example, working with data structures (arrays, lists, matrices, hash-tables, binary trees) and basic algorithms (searching, sorting, searching in tree structures, recursion, etc.).
Algorithmic thinking skill can be seriously developed at the beginner courses for software engineers at SoftUni as well as in specialized algorithmic courses like those covering data structures and algorithms.
As you can guess the programming language doesn't matter for the development of algorithmic thinking. To think logically is a universal skill, and it's not related only to programming. Because of the well-developed logical thinking it's believed that programmers are smart people.
Fundamental knowledge and skills for programming, software development, software engineering and computer science comprise around 25% of the developer's minimum skills to start a job. Here are the more important of these skills and knowledge:
- basic mathematical concepts related to programming: coordinate systems, vectors and matrices, discrete and non-discrete mathematical functions, state automata and state machines, combinatorics and statistics concepts, algorithm complexity, mathematical modeling and others
- programming skills – code writing, working with data, using conditional statements and loops, working with arrays, lists and associative arrays, strings and text processing, working with streams and files, using programming interfaces (APIs), working with IDE, debugger, developer tools, etc.
- data structures and algorithms – lists, trees, hash-tables, graphs, search, sorting, recursion, binary search trees, etc.
- object-oriented programming (OOP) – working with classes, objects, inheritance, polymorphism, abstraction, interfaces, data encapsulation, exceptions management, design patterns
- functional programming (FP) – working with lambda functions, higher order functions, functions that return a function as a result, closure, etc.
- databases – relational and non-relational databases, database modeling (tables and links between them), SQL query language, object-relational mapping (ORM), transactions and transaction management
- network programming – network protocols, network communication, TCP/IP, concepts, tools and technologies from computer networks
- client-server interaction, peer to peer communication, back-end technologies, front-end technologies, MVC architectures
- technologies for server development **(back-end) **– Web server architecture, HTTP protocol, MVC architecture, REST architecture, web development frameworks, templating engines
- web front-end technologies (client-side development) – HTML, CSS, JS, HTTP, DOM, AJAX, communication with back-end, calling REST API, front-end frameworks, basic design and UX (user experience) concepts
- mobile technologies – mobile apps, Android and iOS development, mobile user interface (UI), calling server logic
- embedded systems – microcontrollers, digital and analog input and output control, sensor access, peripheral management
- operating systems – working with operating systems (Linux, Windows, etc.), installation, configuration and basic system administration, process management, memory, file system, users, multitasking, virtualization and containers
- parallel and asynchronous programming – thread management, asynchronous tasks, promises, common resources, and access synchronization
- software engineering – source control systems, development management, task planning and management, software development methodologies, software requirements and prototypes, software design, software architectures, software documentation
- software testing – unit testing, test-driven development, QA engineering, error reporting and error tracking, automation testing, build processes and continuous integration
We need to clarify once again that the programming language does not matter for the assimilation of all these skills. They accumulate slowly, over many years of practice in the profession. Some knowledge is fundamental and can be learned theoretically, but for their full understanding and in-depth awareness, you need years of practice.
Fundamental knowledge and skills for programming, software development, software engineering, and computer science are taught during the Software Engineering Program, as well as a number of elective courses. Working with a variety of software libraries, APIs, frameworks and software technologies and their interaction gradually builds this knowledge and skills, so do not expect that you will understand them from a single course, book or project.
To start working as a programmer, only basic knowledge in the areas listed above is enough and the improvement happens at the workplace according to the technology and development tools used in the company and the team.
Programming languages and software development technologies form around 25% of a programmer's skills. They have the largest learning content, but they change very fast over time. If we look at the job offers in the software industry, they usually mention words like the ones below, but in the job offers they secretly mention the three main skills: coding, algorithmic thinking and knowing the fundamentals of computer science and software engineering.
For those clearly technological skills the programming language does matter.
- Note: only for these 25% of the profession the programming language does matter!
- For the rest 75% of the skills the programming language doesn't matter, and these skills are resistant in time and transportable between different languages and technologies.
Here are some commonly used software development stacks which software companies are looking for (as of Jan 2019):
- Java + Java API classes + OOP + FP + databases + MySQL + HTTP + web programming + HTML + CSS + JS + DOM + jQuery + JSP / Servlets + Spring MVC or Java EE / JSF + cloud + containers
- C# + OOP + FP + classes from .NET + SQL Server databases + Entity Framework (EF) + ASP.NET MVC + HTTP + HTML + CSS + JS + DOM + jQuery + cloud + containers
- JavaScript (JS) + OOP + FP + databases + MongoDB or MySQL + HTTP + web programming + HTML + CSS + JS + DOM + jQuery + Node.js + Express + Angular or React + cloud + containers
- Python + OOP + FP + databases + MongoDB or MySQL + HTTP + web development + HTML + CSS + JS + DOM + jQuery + Django or Flask + cloud + containers
- PHP + OOP + databases + MySQL + HTTP + web development + HTML + CSS + JS + DOM + jQuery + Laravel or Symfony or other MVC framework for PHP + cloud + containers
- C++ + OOP + STL + Boost + native development + databases + HTTP + other languages and technologies
- Swift + OOP + MacOS + iOS + Cocoa + Cocoa Touch + XCode + HTTP + REST + other languages and technologies
- Go + OOP + Linux + Protobuf + gRPC + cloud + containers + other languages and technologies
If the words above look scary and absolutely incomprehensible, then you are at the very beginning of your career and you need many years of learning until you reach the profession of a "software engineer". Do not worry, every programmer goes through one or several technology stacks and needs to study a set of interconnected technologies, but the bottom line is the ability to write programming logic (coding), and the skill of algorithmic thinking (to solve programming problems). It's impossible without them!
As it already became clear, the difference between programming languages and more specifically between the skills of developers in different languages and technologies forms around 10-20% of the skills.
- All programmers have around 80-90% of the same skills that do not depend on the programming language! These are the skills to program and to design and develop software, that are very similar in different programming languages and development technologies.
- The more languages and technologies you know, the faster you will learn new ones, and the less you will feel the difference between them.
Indeed, the programming language almost does not matter, you just have to learn to program, and this starts with coding (this book) goes on in the more complex programming concepts (like data structures, algorithms, OOP and FP) and includes the use of fundamental knowledge and skills for software development, software engineering and computer science.
Only when you start working with a specific technology into a software project you will need a specific programming language, knowledge about specific programming libraries (APIs), frameworks and software technologies (front-end UI technologies, back-end technologies, ORM technologies, etc.). Keep calm, you will learn them, all programmers are learning them, but first you need to learn the foundation: to program and do it well.
This book uses the Java language, but it is not required and can be replaced with Java, JavaScript, Python, PHP, C++, Ruby, Swift, Go, Kotlin, or any other language. To be a software developer, you need to learn coding (20%), learn algorithmic thinking, and solve problems (30%), to have fundamental knowledge of programming and computer science (25%) and to master a specific programming language and the technologies around it (25%). Be patient, for a year or two all this can be mastered on a good starting level, if you are serious.
The general head of the project for creating the free programming book for beginners with an open-source code is Dr. Svetlin Nakov. He is the main ideologist and author of the learning content of the training course "Programming Basics" in SoftUni, which was used as the basis of the book.
Everything started with the mass free programming basics courses that have been conducted in the whole country since 2014, when the SoftUni initiative was launched. At the beginning these courses had larger range and covered more theory, but in 2016 Dr. Svetlin Nakov completely revised, updated and simplified the whole method of teaching, strongly emphasizing on practice. This is how the core of the learning content of this book was created.
The free courses at SoftUni for introduction to programming, are probably the most massive trainings ever conducted in South-Eastern Europe. Until 2017 the course in programming basics was held over 150 times, in around 40 Bulgarian towns and cities in person and multiple times online with over 50 000 participants. It was completely natural to write a book for the tens of thousands of participants at the SoftUni basic programming course. Following the principle of free software and free knowledge, Svetlin Nakov led a team of volunteers and started this open-source project. At first the idea was to create a free book for the basics of programming in C# programming language and later to extend the initiative with other similar books in various popular programming languages (like Java, JavaScript and Python). This book is almost a mirror translation to Java from its original version in C#.
The project is part of the hard work of the Software University Foundation to create and distribute an open learning content to teach software engineers and IT professionals.
This book is developed by a broad author's team of volunteers who dedicated their time to give away the systematized knowledge and guide you at the start of programming. Below is a list of all authors and editors (in alphabetical order.)
Asya Dikova-Kirova, Vaydin Kachanov, Ventsislav Petrov, Daniel Tsvetkov, Dimitar Dalev, Zhulieta Atanasova, Ivaylo Ivanov, Kristiyan Pamidov, Milena Georgieva, Nikolay Bankin, Petar Ivanov, Rositsa Nenova, Svetlin Nakov, Teodor Kurtev, Tsvetan Georgiev
The book is based on its initial C# variant (Introduction to Programming with C#) which is developed by a large team of authors that has a significant contribution to the current book:
Aleksandar Krastev, Aleksandar Lazarov, Angel Dimitriev, Vasko Viktorov, Ventsislav Petrov, Daniel Tsvetkov, Dimitar Tatarski, Dimo Dimov, Diyan Tonchev, Elena Rogleva, Zhivko Nedyalkov, Zhulieta Atanasova, Zahariya Pehlivanova, Ivelin Kirilov, Iskra Nikolova, Kalin Primov, Kristiyan Pamidov, Lyuboslav Lyubenov, Nikolay Bankin, Nikolay Dimov, Pavlin Petkov, Petar Ivanov, Rositsa Nenova, Ruslan Filipov, Svetlin Nakov, Stefka Vasileva, Teodor Kurtev, Tonyo Zhelev, Hristiyan Hristov, Hristo Hristov, Tsvetan Iliev, Yulian Linev, Yanitsa Valeva
Book cover design: Marina Shiderova.
The book Programming Basics with C# is available for free at the following web address:
This is the official book site and any new version will be uploaded there. The book is mirrored in the other programming languages mentioned on the website.
Ask your questions about basic programming book at the SoftUni's Facebook page or in the official SoftUni discussion forum:
In these discussion channels you will get proper response to any question associated with the content of this book also any other questions about programming. The SoftUni community is so big that you will get a response within a few minutes. The trainers, assistants and mentors at SoftUni also respond to your questions. Note that the forum can hold questions in different languages (English, Bulgarian and others), but if you ask in English, you will get an answer in English.
Because of the big number of learners, you can find in the forum practically any solution of any exercise, shared by your colleague. Thousands of students already got the answer on the same exercise, so if you are late you can check the forum. Even though the exercises in "Programming Basics" are changing at some point, the sharing at SoftUni is always welcome and encouraged, that's why you will easily find solutions and guidance for any exercise.
If you do have a specific question, for example if you spend many hours on certain piece of code and it doesn't work correctly, you can always ask in the forum. You will be surprised how friendly are the SoftUni's forum participants.
The book has an official Facebook page where you can track the news about the book series "Programming Basics", new releases, events and initiatives:
The book is distributed freely in electronic format under an open license CC-BY-NC-SA.
The book is published and distributed on paper by SoftUni and you can buy a hard copy from online bookstores like Amazon.
You can find the source code of the book in GitHub: https://github.com/SoftUni/Programming-Basics-Book-Java-EN.
International Standard Book Number (ISBN): 978-619-00-0636-7.
If you find mistakes, inaccuracies or bugs in the book, you can report them in the official bug tracker of the project:
https://github.com/SoftUni/Programming-Basics-Book-Java-BG/issues
We do not promise to fix everything you send us, but we do want to always improve the quality of the book, so the reported errors and reasonable suggestions will be reviewed.
Don't forget to write code in large quantities, to test the examples that you'll find in the end of each chapter and more importantly to solve the problems from the exercises. You won't learn to program from just reading the book, what will help is to solve as many problems as you can find!