I came across a very good list of best java books, it had helped me. Feel free to comment, ask questions if you have any doubt. Pages Home core java spring online courses thread java 8 coding sql books oop interview certification free resources best. Every Java programmer loves free eBooks on Java, don't you? When I shared my collection of top 10 Java programming books , one of my readers asked me to share some free Java books as well.
Doing a quick search on the internet reveals lots of free books, resources, and tutorials to learn Java. These books are an excellent resource for any Java beginners, as well as an experienced programmer, and since they are free, it makes absolute sense to have a look on this before buying any other book in Java.
Though books like Effective Java or Java Concurrency in Practice are not free, they are worth every penny spent. A good book to learn Java8 absolutely free. It's the 11th book in this list, which started with just 7 books. Update: 2 I have added a couple of new free Java programming eBooks from O'Reilly which will teach you latest and greatest in Java, e.
Btw, if you want, you can also combine these free books with a comprehensive online course like The Complete Java Masterclass to get the best of both worlds. It's also most up-to-date resource and covers changes on recent Java versions up to Java Without wasting any more time, here is the list of some of the great Java books, which are absolutely FREE, you don't need to pay anything to download or read this book.
All you need is an internet connection to download these books on your computer, laptop, iPhone, or Android smartphone. Many Thanks to O'Rilley who has published an introductory book on Java 8, titled with Introducing Java 8, A quick start guide to lambda expressions and streams.
The author Raoul-Gabriel Urma, who is also an author of one of the best seller book of last year, Java 8 in Action , explains how improved code readability and support for multicore processors were the prime movers behind Java 8 features. Along with books, there are a lot of free courses to learn Data Structure and Algorithms.
I have done some hard work and also published a list of my favorite Free Data Structure and Algorithms courses you should also check them to learn this important topic better. It's completely free. You can download entire books as PDF, along with all example programs. Carl Albing and Michael Schwarz have done an excellent job to put everything needed to run and support a Java program in Linux environment including how to start, stop, or kill Java process, checking logs with some handy useful UNIX commands.
Paperback edition of this book is also available here on Amazon. Paperback edition of this Java book is also available for purchase on Amazon, here. Labels: books , core java , free resources , programming. You can stick a number like After you place a number in the variable, you can change your mind and put a dif- ferent number into the variable.
Of course, when you put a new number in a variable, the old number is no longer there. Figure gives a before-and-after picture of the code in Listing After the first statement in Listing is executed, the variable amountInAccount has the number Then, after the second statement of Listing is exe- cuted, the amountInAccount variable suddenly has On the left side of Figure , imagine that the box with Figure A variable before and after.
Now you need some terminology. The thing stored in a variable is a value. For instance, you can create a variable that always stores a letter. Even in formal writing, I often use the word variable when I mean variable name. Strictly speaking, amountInAccount is a variable name, and all the memory storage associated with amountInAccount including the type that amountInAccount has and whatever value amountInAccount currently represents is the variable itself.
If you think this distinction between variable and variable name is too subtle for you to worry about, join the club. Every variable name is an identifier — a name that you can make up in your own code. In preparing Listing , I made up the name amountInAccount. For more information on the kinds of names in a Java program, see Chapter 3.
Before the sun sets on Listing , you need to notice one more part of the listing. The listing has Anybody in his or her right mind would call these things numbers, but in a Java program it helps to call these things literals. Well, think about the variable amountInAccount in Listing The variable amountInAccount stands for You could use the word number to talk about amountInAccount. But really, what amountInAccount stands for depends on the fashion of the moment.
On the other hand, Starting with Java 7, you can add underscores to your numeric literals. Instead of using the plain old If you want to write 1,, For more information about formatting, check Chapters 10 and Assignment Statements Statements like the ones in Listing are called assignment statements.
In an assignment statement, you assign a value to something. In many cases, this something is a variable. I recommend getting into the habit of reading assignment statements from right to left. Figure illustrates the action of the first line in Listing The second line in Listing is just a bit more complicated.
Figure illus- trates the action of the second line in Listing In an assignment statement, the thing being assigned a value is always on the left side of the equal sign. Figure The action of the second line in Listing Pretty cool, eh? These commercials show 0s zeros and 1s ones sailing by because 0s and 1s are the only things that computers can really deal with.
When you think a computer is storing the letter J, the computer is really storing Everything inside the computer is a sequence of 0s and 1s.
As every computer geek knows, a 0 or 1 is called a bit. The same sequence can also stand for 1. In fact, if the bits are interpreted as screen pixels, the same sequence can be used to represent the dots shown in Figure The meaning of depends on the way the software interprets this sequence of 0s and 1s.
Figure An extreme close-up of eight black and white screen pixels. So how do you tell the computer what stands for? The answer is in the concept of type. The type of a variable is the range of values that the variable is permitted to store. I copied the lines from Listing and put them into a complete Java program. The program is in Listing When I run the program in Listing , I get the output shown in Figure A text-based program has no windows, no dialog boxes — nothing of that kind. All you see is line after line of plain, unformatted text.
The user types something, and the computer displays a response beneath each line of input. As visually unexciting as such programs may be, they contain the basic concepts for all computer program- ming.
So in this book I take a two-pronged approach. These fancier versions have windows, buttons, text fields, and other elements of a typical graphical user interface GUI. In Listing , look at the first line in the body of the main method. In this variable declaration, the word double is a Java keyword. This word double tells the computer what kinds of values you intend to store in amountInAccount. In particular, the word double stands for numbers between —1.
These are enormous numbers with zeros before the decimal point. The second of these numbers is one-point- eight gazazzo-zillion-kaskillion. The number 1. After you declare amountInAccount to be of type double, you can store all sorts of numbers in amountInAccount.
You can store Instead, I would have had to store plain old 50, without any digits beyond the decimal point. Another type — type float — also allows you to have digits beyond the decimal point. In many situations, you have a choice. You can declare certain values to be either float values or double values. For most programs, just use double. When you declare a variable to be of type float, the computer keeps track of only 32 bits.
You could change Listing and declare amountInAccount to be of type float. You could easily store Heck, you could store The accuracy matters. To store the. Do you really believe what you just read — that it takes more than 32 bits to store. To help convince you, I made a few changes to the code in Listing I made amountInAccount be of type float.
Compare this with the output in Figure When I switch from type double to type float, Charles has an extra three cents in his account. Another difficulty with float values is purely cosmetic.
Look again at the literals, The Laws of Java say that literals like these take up 64 bits each. To compensate, you can switch from double literals to float literals by adding an F to each double literal, but a number with an extra F at the end looks funny. The page takes any number that you enter and shows you how the number would be represented as 32 bits and as 64 bits. In a Java program, the best way to represent currency is to shun the double and float types and opt instead for a type named BigDecimal.
Displaying Text The last three statements in Listing use a neat formatting trick. You want to display several different things on a single line on the screen. You put these things in separate statements. All but the last of the statements are calls to System. The last statement is a call to System. Calls to System. After executing System.
With sev- eral calls to print capped off by a single call to println, the result is just one nice-looking line of output. Refer to Figure A call to System. Clearly, whole numbers have a role in this world.
Therefore, in Java, you can declare a variable to store nothing but whole numbers. Listing shows a program that uses whole number variables. So here goes: You have a hotel elevator whose weight capacity is 1, pounds.
One week- end, the hotel hosts the Brickenchicker family reunion. A certain branch of the Brickenchicker family has been blessed with identical dectuplets ten siblings, all with the same physical characteristics. Normally, each of the Brickenchicker dectuplets weighs exactly pounds. But on Saturday, the family has a big catered lunch, and, because lunch included strawberry shortcake, each of the Brickenchicker dectuplets now weighs pounds.
Immediately after lunch, all ten of the Brickenchicker dectuplets arrive at the elevator at exactly the same time. Why not? All ten of them think alike. So, the question is, how many of the dectuplets can fit on the elevator? Now remember, if you put one ounce more than 1, pounds of weight on the elevator, the elevator cable breaks, plunging all dectuplets on the elevator to their sudden and costly deaths.
The answer to the Brickenchicker riddle the output of the program of Listing is shown in Figure Figure Save the Bricken- chickers. At the core of the Brickenchicker elevator problem, you have whole numbers — numbers with no digits beyond the decimal point.
This fact is reflected nicely in Java. An int value is a whole number. When you divide one int value by another www. But if you are byte, short, int, and long. Unlike the need to store numbers larger than , complicated story about the accuracy of types forsake int in favor of long. A long number float and double, the only thing that mat- can be as big as For the ters when you choose among the whole number whole story, see Table You see this in Figure For instance, to create an int variable named weightOfFred and a double variable named amountInFredsAccount, you need two separate variable declarations.
You can give variables their starting values in a declaration. In Listing for instance, one declaration can replace several lines in the main method all but the calls to print and println.
Believe it or not, keeping this distinction in mind is helpful. Sometimes, concise code is easier to read. For an example, see Chapter 7. The nature of your code forces you either to initialize or not to initialize.
The Java language has exactly eight primitive types. As a newcomer to Java, you can pretty much ignore all but four of these types. As programming languages go, Java is nice and compact that way.
Table shows the complete list of primitive types. Previous sections in this chapter cover the int and double types. So, this section covers char and boolean types. The char type Not so long ago, people thought computers existed only for doing big number- crunching calculations.
Nowadays, with word processors, nobody thinks that way anymore. Listing has a simple program that uses the char type. Figure shows the output of the program in Listing In the initialization, notice how b is surrounded by single quote marks. In Java, every char literal starts and ends with a single quote mark. In a Java program, single quote marks surround the letter in a char literal. In the second initialization of Listing , the program calls an API method whose name is Character.
The Character. In the old ASCII representation, each character takes up only 8 bits, but in Unicode, each character takes up 8, 16, or 32 bits.
Occasionally, this bites you in the back or it bytes you in the back, as the case may be. The method Character. To find out more about this, see Chapter 7. The boolean type A variable of type boolean stores one of two values — true or false. Listing demonstrates the use of a boolean variable. In Listing , the allTenOkay variable is of type boolean. To find a value for the allTenOkay variable, the program checks to see whether numberOfPeople is greater than or equal to ten.
Any part of a Java program that has a value is an expression. So, in the statement in Listing , in which allTenOkay is assigned a value, the allTenOkay variable is assigned a false value. In Listing , I call System. In Listing , System. The Molecules and Compounds: Reference Types By combining simple things, you get more complicated things. A more complicated type called a reference type. The program in Listing uses reference types. Figure shows you what happens when you run the program in Listing Both types are defined in the Java API.
Figure An empty frame. A String is a bunch of characters. So, with the myTitle variable declared to be of type String, assigning "Blank Frame" to the myTitle variable makes sense in Listing In a Java program, double quote marks surround the letters in a String literal.
A Java JFrame is a lot like a window. The only difference is that you call it a JFrame instead of a window. To keep Listing short and sweet, I decided not to put anything in my frame — no buttons, no fields, nothing. The big thing to get from Listing is that the program www. In writing the program, I made up two variable names — myTitle and myFrame. Every class is the name of a reference type.
Every Java class is a reference type. Now, when you declare a variable to have type int, you can visualize what that declaration means in a fairly straightforward way. In the storage location is a bunch of bits. The arrangement of the bits ensures that a certain whole number is represented. That explanation is fine for primitive types like int or double, but what does it mean when you declare a variable to have a reference type?
What does it mean to declare variable myFrame to be of type JFrame? Well, what does it mean to declare i thank You God to be an E. Cummings poem? What would it mean to write the following declaration? Because JFrame is a class, you can create objects from that class.
See Chapter 1. Each object each instance of the JFrame class is an actual frame — a window that appears on the screen when you run the code in Listing This reservation tells the computer that myFrame can refer to an actual JFrame-type object.
In other words, myFrame can become a nickname for one of the windows that appears on the computer screen. Figure illustrates the situation. On that same line of code, the phrase new JFrame creates a new object an instance of the JFrame class. Knowing that the two words new JFrame create an object can be very important. For a more thorough explanation of objects, see Chapter 7. Figure The variable myFrame refers to an instance of the JFrame class. Therefore, deep Notice that this high and mighty thing called inside the declaration of the Frame class, you a Java API class is neither high nor mighty.
Some of those variable dec- int height; larations use primitive types, and other variable int x; declarations use reference types.
An instance and the declarations of those classes have of the Time class may have an hour a number variables. The chain goes on and on. Ultimately, from 1 to 12 , a number of minutes from 0 to 59 , everything comes, in one way or another, from and a letter a for a. In addi- tion, Barrymore was a writer, composer, and director. Barrymore did the voice of Ebenezer Scrooge every year on radio. In addition, Barrymore not Ethel, John, or Drew was a writer, composer, and director. Lionel Barrymore did the voice of Ebenezer Scrooge every year on radio.
The same is true in a Java program. Look again at Listing import javax. You clarify what you mean by JFrame with the full name javax.
JFrame name wherever you use the name JFrame in your code. But fortunately, many IDEs have convenient helper features for import declarations. No single section in this book can present the entire story about import dec- larations.
It was the first thing that you learned about in elementary school math. Almost every- body knows how to add 2 and 2. You can use it for several purposes. I'm dreaming about the history course that I failed in high school.
You can even use the plus sign to paste numbers next to String values. When you divide an int value by another int value, you get an int value. Instead, the computer chops off any remainder.
If you put System. Another useful arithmetic operator is called the remainder operator. When you put System. It does this because 4 goes into 11 who-cares-how-many times with a remainder of 3.
The remainder operator turns out to be fairly useful. Listing has an example. Listing Making Change import static java. You start with a total of cents.
That means you can make 9 quarters from cents. Import declarations: The ugly truth Notice the import declaration at the top of For the real story about static, you have to read Listing part of Chapter For now, rest assured that import javax. And By adding the import static java. If you remove the Java program do not use the word static.
Unfortunately, System. Well, to be honest, I wish out is not the name of a class. With these denominations, the MakeChange class gives you more than simply a set of coins adding up to cents. The MakeChange class gives you the smallest number of coins that add up to cents. You can always get a set of coins adding up to a total. The other two lines are assignment statements. To find out what a block is, see Chapter 5. Then, for some honest talk about redeclaring variables, see Chapter Altogether, four such operators exist — two increment operators and two decrement operators.
To see how they work, you need some examples. The first example is in Figure Figure shows a run of the program in Figure In this horribly uneventful run, the count of bunnies prints three times. The double plus signs go by two names, depending on where you put them. The pre stands for before. Figure Using prein- crement. Figure A run of the code in Figure To understand this, look at the bold line in Figure The computer adds 1 to numberOfBunnies raising the value of numberOfBunnies to 29 and then prints 29 onscreen.
An alternative to preincrement is postincrement. The post stands for after. To see more clearly how postincrement works, look at the bold line in Figure The computer prints the old value of numberOfBunnies which is 28 on the screen, and then the computer adds 1 to numberOfBunnies, which raises the value of numberOfBunnies to With out.
Figure shows a run of the code in Figure Figure Using post- increment. But occasionally some means out. I discuss statements in Chapter 3, and I OfBunnies. The surprising answer is both. The OfBunnies is Bunnies , the computer adds 1 to the Assume that, before the computer executes variable numberOfBunnies, and the code the code out. Bunnies is Try no longer. Most programmers use postincrement.
In addition to preincrement and postincrement, Java has two operators that use These operators are called predecrement and postdecrement. This is entirely incorrect. On top of that, when you write numberOfBunnies only once, you have only one chance instead of two chances to type the vari- able name incorrectly. Assignment operators If you read the preceding section, which is about operators that add 1, you may be wondering whether you can manipulate these operators to add 2 or add 5 or add If you try it, an error message appears when you try to compile your code.
So what can you do? As luck would have it, Java has plenty of assignment operators that you can use. With an assignment operator, you can add, sub- tract, multiply, or divide by anything you want.
You can do other cool opera- tions, too. Listing has a smorgasbord of assignment operators the things with equal signs. Figure shows the output from running Listing With the assignment operators, you can add, subtract, multiply, or divide a variable by any number.
You can use an assignment operator as part of a larger Java statement. In the next to last line of Listing , the operator subtracts 7 from numberOfBunnies, decreasing the value of numberOfBunnies from to Then the whole assignment business is stuffed into a call to System. The thing that I call an assignment statement near the start of this chapter is really one of the assignment opera- tors that I describe in this section.
Therefore, whenever you assign a value to something, you can make that assignment be part of a larger statement. Each use of an assignment operator does double duty as a statement and an expression.
For example, before executing the code System. So the code System. The number displays on the computer screen. I remember one episode in which Mr. Wilson was having trouble making an important decision. I think it was something about changing jobs or moving to a new town. Anyway, I can still see that shot of Mr.
Wilson sitting in his yard, sipping lemonade, and staring into nowhere for the whole afternoon. Of course, the annoying character Dennis was constantly interrupting Mr. What impressed me about this episode the reason why I remember it so clearly even now was Mr. He was sitting quietly in his yard, making marks carefully and logically on his mental balance sheet. How many people actually make decisions this way? At that time, I was still pretty young.
But I wondered what such a decision-making process would be like. Would it help to sit there like a stump for hours on end? Would I make my decisions by the careful weighing and tallying of options? Or would I shoot in the dark, take risks, and act on impulse? Only time would tell. Did the user correctly type his or her password? If yes, let the user work; if no, kick the bum out. So the Java programming language needs a way of making a program branch in one of two directions.
Guess the number Listing illustrates the use of an if statement. Two runs of the program in Listing are shown in Figure Listing A Guessing Game import static java. Scanner; import java. The program in Listing plays a guessing game with the user. The program gets a number a guess from the user and then generates a random number between 1 and If the number that the user entered is the same as the random number, the user wins.
Otherwise, the user loses, and the program tells the user what the random number was. She controlled keystrokes from the keyboard Taken together, the lines import java. The last of the three lines puts this number into a variable named inputNumber.
You can copy these lines almost word for word whenever you want to read from the keyboard. Include the first two lines the import and Scanner lines just once in your program. Later in your program, wherever the user types an int value, include a line with a call to nextInt as in the last of the preceding three lines of code. Of all the names in these three lines of code, the only two names that I coined myself are inputNumber and keyboard. All the other names are part of Java. So, if I want to be creative, I can write the lines this way: import java.
Other than that, I have very little leeway. But importing Scanner is different from importing System. When you import java. Refer to Listing The difference creeps into the code because Scanner is the name of a class, and System.
For a quick look at the use of the word static in import declarations, see one of the sidebars in Chapter 4. For a more complete story about the word, see Chapter To get characters from some place other than the keyboard, you can type something other than System.
What else can you put inside the parentheses? For some ideas, see Chapter 8. In Listing , I make the arbitrary decision to give one of my variables the name keyboard.
The name keyboard reminds you, the reader, that this variable refers to a bunch of plastic buttons in front of your computer. On the other hand, the name System. If you expect the user to type a double value a number containing a decimal point , use nextDouble.
If you expect the user to type true or false, use nextBoolean. If you expect the user to type a word like Barry, Java, or Hello, use next. Download e-Book. Posted on. Page Count. Mr Kotiyana,. This Java Programming book was written as an answer for anyone to pick up Java Programming Language and be productive. Learn it fast and learn it well. Download e-Book Pdf. Related e-Books.
0コメント