I have been programming in Java for 7 years now. But at work, you often have to train a new generation. In this regard, I decided to make some cheat sheet, which, I hope, will be useful for Habrchan. If someone can help supplement the information from this article with something, then write! So:
Essential Resources for Initial Learning
- www.javable.com - a site with articles and a tutorial on Java. Everything is mostly in Russian.
- www.exampledepot.com - very useful resource where collected brief examples using classes for certain packages
- java.sun.com - you can't do without the original source. For any Java programmer, JavaDoc should be the ultimate truth. Also here you can find a series of tutorials on all possible topics.
Basic Java packages
Below is a list of Java packages that a programmer should be fluent in. It is recommended to get acquainted with them both by JavaDocs and with the help of www.exampledepot.com. All packages are arranged in the recommended order for study. So:- java.lang is the foundation of the basics. Each class in this package needs individual attention.
- java.io - no program can do without I/O operations.
- java.util - The package basically contains everything you need to work with collections: Collection, Enumeration, Set, List, Map, etc. etc.
- java.net - contains the main classes for working with the network.
- java.text - everything you need to format text
- java.lang.reflect - Java wouldn't be Java if it wasn't for Reflection. Reflection blurs the line between data and code.
- javax.sql - everything you need to work with databases
- javax.xml.* , org.w3c.dom.* , org.xml.sax.* - working with XML is simply unthinkable without these packages
Resources to broaden your horizons
- onjava.com - sooner or later, all the news from the Java world ends up here
- www.javaspecialists.eu - a resource useful for both beginners and advanced programmers, as it contains many articles about the intricacies of working with Java.
- www.theserverside.com - It is recommended to subscribe to the RSS, as very interesting things about Java often slip through.
Java Libraries Everyone Should Know
Java doesn't end with just knowing the features of the JSDK. To feel comfortable, you need to know about a dozen or two third-party libraries used by Java programmers everywhere. So let's start with the basics:- Commons Lang - what is "forgotten" to include in the JDK
- Commons Math is a great addition to java.math
- Commons Logging - logging must be competent. For System.out.println to display logs, novice programmers should chop off their hands after a week of training.
- 2 months Java learning EE (2 times a week for 4 hours)
- if you show good results (you defend your project successfully, which you write these two months), then you are offered a job.
- Performing practical tasks at home.
- If successful, you will be invited to computer testing in the office.
- In case of successful testing, you will be interviewed on the same day.
- how checked exceptions differ from unchecked;
- what methods does the Object class have and why are they needed;
- what collections are and why they are;
- and a little about multithreading.
Java for dummies. Lesson 1. Program Hello World!
First, I'll tell you what Java can do. Firstly, in this language, you can write applets - programs that are embedded in the web page of the site. For example, it can be a game, a business graphics system, and much more. Secondly, you can write full-fledged applications in Java that are not necessarily related to the Web. And servlets are also possible - programs that, unlike applets, are executed not on the client side, but on the server side.
Let's start with the very basics. Let's pay tribute to tradition and write the simplest program which displays the greeting hello world. If you don't have Java, then it can be downloaded from the official site http://www.java.com/en. Then install it.
If Java you have installed, then type in some editor the following text:
Public class HelloWorld { public static void main ( String args ) { System . out . print ( "Hello, world!" ); } } |
And be sure to save it under the name Hello World. java- the name of the executable class must match the name of the file. To compile, use the program javac.exe included in the standard package Java. Here's what a compilation batch file might look like this java file:
"c:\Program Files\Java\jdk1.7.0\bin\javac" HellowWorld.java pause |
If there are no errors during compilation:
then, most likely, the compilation was successful and you have it in the same directory where HellowWorld was. java HellowWorld also appeared.class:
Now let's run another batch file that will call the Java interpreter along with our compiled file:
"c:\Program Files\Java\jdk1.7.0\bin\java" HellowWorld pause |
If everything is done correctly, then you should get the following result:
If you got it, then I can congratulate you - you have written your first Java program. In the future, we will learn how to write Java applets, and much more. And now a few words about the program itself. As you can see, it starts with the word public. This is a modifier that means that we are declaring something public: a class, a class method, or a variable. There are other modifiers, for example: private, protected, friendly, final, abstract, static. Some of them can be combined with each other. For example, private means that the variable we want to declare is private to other classes. But we will get to the modifier. Now consider the following class keyword. It means that we are declaring a class. Everything in java is based on classes. One of the classes must be the base class. And the base class must be public. In this example, this is the HelloWord class. For now, he's the only one we have.
Now I'll try to explain in simple terms, what is Class and what is an object.
Recall the school course of zoology. How is the living world classified? First, the concept of "kingdom" is introduced.
1. The kingdom of unicellular,
2. plant kingdom
3. Animal Kingdom.
Let's take animals. They can be divided into types. For example:
1. Type intestinal.
2. Type flatworms.
3. Shellfish type.
4. Type chordates.
The latter are divided into mammals, reptiles, amphibians, birds, etc. You can go even further into the classification, but now we will not do this, but will go directly to programming.
In the Java language, you can, like the classification of the living world, classify objects (pieces of program and data). It has classes for this.
Stop stop! - you say, - why classify these objects?
Imagine that you, like some kind of demiurge (creator, god), create life on Earth. First you developed the simplest organic compounds. So, for the sake of experiment, what happens. Then they combined them into complex molecules, from which, like bricks, they assembled the simplest microorganisms. But your ultimate goal is to create intelligent life. Therefore, you did not stop there, but created multicellular organisms. Then they began to improve and develop them. Some species were viable, some became extinct (dinosaurs). And finally, the goal was achieved - Homo Sapiens appeared - a reasonable person.
And now let's descend from heaven to earth and imagine programming as a creation, where you force your program to evolve to a certain state, when it can be used, and then further, gradually increasing and improving functionality.
Now imagine that an atom is the simplest command programs or a unit of information (which, you see, are inseparable from each other, because the program works with what - correctly, with information).
Then the molecule is a subroutine. Or an object.
Here we have created a bunch of objects in our program. It is necessary to classify them somehow, so as not to get confused. That's what Java provides for classes ( class ). With the help of them, we describe the class of objects ( general concept, for example, birds), and then, having the described class, we can create an object - an instance of this class. That is, the class is the very word Birds, and the object is some kind of specific bird, if we continue our analogy.
Further, birds are different types. But they all have common features, inherited from the concept of "Birds". So in Java, you can create another class from a class that inherits its properties and methods (features). It is called inheritance.
Different birds have different colors of feathers, the shape of the beak and wings. So for classes, when creating a new class, inherited characteristics can be changed. It is called polymorphism.
So, with the basic concepts of Java figured out. Now let's go through the program.
This is how we declare the class:
public class HelloWorld { |
In this case, there is only one class in our program, and this is the base class, that is, the class responsible for starting the program. That is why its name must match the file name, so that the interpreter "knows" where to start the program execution.
The base class (HelloWorld ) has base method:main. We have declared it as public and static. The first one indicates that this method is public. If this were not so, then the program would simply not start. There are also methods that are not public, but we will talk about them in the next lessons, for now just remember that the base method (which we run when the program starts) must be public. And its name should be main so that the interpreter knows where to start executing the program.
Now what is static. This is a modifier that indicates that the method is static. That is, it works even when an instance of the class (object) has not been created. In general, fields and methods with the static modifier are common to all objects of the class. We will also talk about this later.
Each method may or may not have a return value. If it does, then it's a function. The return type is also set in the method declaration. If not, then put void (as in our example).
Access to the fields and methods of the object goes through a dot. There are also built-in objects, for example, System, which we use in our example:
System . out . print ( Hello world! ); |
in this case, we refer to the out field, which is also an object intended for data output, and call its print method, which displays text on the screen (as in the good old BASIC, the PRINT command).
(C) Shuravin Alexander
Java is considered one of the most significant and widely used programming languages because of its unique role in the development of applications for the Internet.
The purpose of this book is to teach you, the reader, the fundamentals of programming in Java language. It takes a step-by-step approach to language learning through numerous examples, self-test exercises, and simple projects. For learning Java This book does not require any prior programming experience. The book starts with the most basic concepts, including compiling and running Java programs. Then we will talk about keywords and linguistic means and constructions that make up Java foundation. After that, more advanced Java language features are covered, including multi-threaded programming and generics. And the book ends with an introduction to the Swing library. All this will give you a clear understanding of the basics of Java programming.
Origins of Java.
The main reasons for creating a new programming language are the improvement of the art of programming or changes in the computing environment. And Java is no exception to this rule. Drawing on the rich legacy of C and C++, this programming language has been refined and enhanced with tools that reflect the current state of the art in programming. Responding to the needs of the emerging interactive environment, Java provides tools that make it easy to create application programs with a highly distributed architecture.
Java was conceived in 1991 by Sun Microsystems employees James Gosling, Patrick Naughton, Chris Warth, Ed Frank, and Mike Sheridan. At first, this language was named Oak, but in 1995 it was renamed Java. Oddly enough, the developers of the language did not originally intend it for the development of Internet applications. They sought to create a platform-independent language in which to create an embeddable software for various household appliances with microprocessor control, including toasters, microwave ovens and consoles remote control. Such devices used controllers based on microprocessors of different architectures, and the executable code generated by the compilers of most of the programming languages that existed at that time was focused on a specific processor. A typical example of this is the C++ language.
Table of contents
Introduction
Chapter 1 Java Basics
Chapter 2 Introduction to Data Types and Operators
Chapter 3 Control Statements
Chapter 4 Introduction to Classes, Objects, and Methods
Chapter 5 additional information about data types and operators
Chapter 6. More about methods and classes
Chapter 7
Chapter 8 Packages and Interfaces
Chapter 9 Exception Handling
Chapter 10 Data I/O
Chapter 11 Multithreaded Programming
Chapter 12 Enums, Autoboxing, Static Imports, and Annotations
Chapter 13 Generalizations
Chapter 14: Applets, Events, and More
Chapter 15 Introduction to Swing
Appendix A. Answers to self-test questions
Appendix B. Using Documentation Comments in Java Index.
Free download e-book in convenient format, watch and read:
Download book Java, A Beginner's Guide, Herbert Schildt, 2012 - fileskachat.com, fast and free download.
I have been programming in Java for 7 years now. But at work, you often have to train a new generation. In this regard, I decided to make some cheat sheet, which, I hope, will be useful for Habrchan. If someone can help supplement the information from this article with something, then write! So:
Essential Resources for Initial Learning
- www.javable.com - a site with articles and a tutorial on Java. Everything is mostly in Russian.
- www.exampledepot.com - a very useful resource, which contains brief examples of using classes for certain packages
- java.sun.com - you can't do without the original source. For any Java programmer, JavaDoc should be the ultimate truth. Also here you can find a series of tutorials on all possible topics.
Basic Java packages
Below is a list of Java packages that a programmer should be fluent in. It is recommended to get acquainted with them both by JavaDocs and with the help of www.exampledepot.com. All packages are arranged in the recommended order for study. So:- java.lang is the foundation of the basics. Each class in this package needs individual attention.
- java.io - no program can do without I/O operations.
- java.util - The package basically contains everything you need to work with collections: Collection, Enumeration, Set, List, Map, etc. etc.
- java.net - contains the main classes for working with the network.
- java.text - everything you need to format text
- java.lang.reflect - Java wouldn't be Java if it wasn't for Reflection. Reflection blurs the line between data and code.
- javax.sql - everything you need to work with databases
- javax.xml.* , org.w3c.dom.* , org.xml.sax.* - working with XML is simply unthinkable without these packages
Resources to broaden your horizons
- onjava.com - sooner or later, all the news from the Java world ends up here
- www.javaspecialists.eu - a resource useful for both beginners and advanced programmers, as it contains many articles about the intricacies of working with Java.
- www.theserverside.com - It is recommended to subscribe to the RSS, as very interesting things about Java often slip through.
Java Libraries Everyone Should Know
Java doesn't end with just knowing the features of the JSDK. To feel comfortable, you need to know about a dozen or two third-party libraries used by Java programmers everywhere. So let's start with the basics:- Commons Lang - what is "forgotten" to include in the JDK
- Commons Math is a great addition to java.math
- Commons Logging - logging must be competent. For System.out.println to display logs, novice programmers should chop off their hands after a week of training.