
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
The tools we will use will be explained.
Using the exercises and checking the solutions, source codes will be explained.
Java became popular by its platform independent architecture.
When you write an application for Windows, you may port it to Mac or any Linux distribution without any further effort. This is amazing.
You will learn how platform independency works.
All new students confuse what is JDK and JRE. JDK is used by only developers and contains development tools like compiler but JRE is used by anyone.
Some basic syntax rules explained.
What is statement in Java?
How to separate statements?
How to define variables and assign values to variables?
How to allocate memory for an object with new keyword.
All the source files used throughout the course is here:
Creating variables and assigning values.
Running our very first application.
Throughout the course you will need to import some projects into the workspace of Eclipse. Thats why you need to learn how to import a project from external source and then export your own code.
Importing means: Using the pre-developed code in your very own development environment.
Exporting means: Packaging the source code of your application so that anyone else can use your code.
Primitives are the exceptions of object oriented Java. Apart from the objects, they don't have any methods, they can not be pass by address value etc. (May not make sense for now, just be familiar with the terms) They are simply used for storing some basic (primitive values).
Simple primitive values are: int, float, long, short, char, boolean.
You will do some mathematical operations on primitive variables.
int is the most known integer type in Java. In case you need to store much greater values, you need to use long type. Because its range is much more greater than int's.
If you will store tiny numbers (namely smaller than 256) you may use short type not to consume more memory.
According to the needs, you may use short, int and long types to represent integer values. In some cases you may need to use them together. In that case you should convert them properly.
Type casting means converting different types to each other and accepting possible data loses so that compiler does not complain about these possible data loses.
You are given heterogenous type of variables in this exercise.
You need to cast the types for acquiring a single result with desired type. Good challenge!
We represent floating point numbers with float and double types.
Default floating point type is double and its range is so wide.
If you will store tinier floating point numbers, you may use float type.
In this case you should append "f" next to each floating point number. Otherwise they will be converted to double automatically.
Mathematical operations have precedence order by default. If you don't change the precedence order will be
1- Multiplication, division, modulus
2- Summation and subtraction
Group 1 and group 2 is executed from left to right among each other.
You will learn
Processors run with boolean algebra. Everything is 0 or 1 or ( true or false)
In any software, you control the execution flow with true and false values also.
True and false values are represented with boolean type.
You will learn boolean types and boolean arithmetics.
Boolean type is a truth-value and denoted by only one bit (0 or 1). In that case, an expression is either true or false. Sometimes we need to combine some values to yield a combined result. Combining operation is done with Boolean algebra. For instance;
“The customers subscribed in last three months who did not pay the bill this month” expression has two boolean values inside:
1. The customers who subscribed in last three months
2. The customers who did not pay the bill.
This expressions can be combined by an and operation: expr1 and not expr2 if 1. expr1: The customers who subscribed in last three months 2. expr2: The customers who did pay the bill. Boolean algebra operations are the conjunction and, the disjunction or, and the negation not. In java, AND operation is denoted by &&, OR operation || and NEGATION operation by ! .
You may write a value into console with
System.out.print() and System.out.println() methods. You may pass any object instance into this method so that they can be represented as String (text).
print and println methods have a simple difference: println methods put a new line character at the end so that lines are broken.
We represent a single character with char type.
Char is an integer corresponding to its ASCII value in fact. So you can change a char variable's value such as an ordinary integer. This is called as char arithmetic:
A char is an integer between 0 and 65535 implicitly. For instance the code below prints A.
char c = 65;
System.out.println(c);
If you increment c by 1, this code will print B.
You will have an hands-on experience with character arithmetic now.
Explore character arithmetic in Java by converting between uppercase and lowercase using ASCII values, such as 65 for 'A' and 97 for 'a', and casting int to char.
When we need to modify the flow according to a condition, we may use if statements. If a Boolean expression is true, we may do something, else something different. This can be visualized with a flow chart.
You will learn how to construct a flow chart and then implement them with if-else blocks.
We will develop an evaluating system for students.
Create a variable to store the exam result.
Our system will print the letter grade according to the
table below such as “Your grade is B for 56.” If the point smaller than 60, system will print “You
may re-attend the exam.”, otherwise “Thanks for attending the exam.”
Switch statement is the alternative to if-else blocks.
If else statements control the execution flow with boolean values. But switch statements control the execution flow with integer, string or enum values.
•Loops is used to do similar thing several times not to copy-paste code several times.
•Loops can be executed as long as a condition is true and can be stopped when this condition is not satisfied.
•Each execution of the same statement is called as “iteration”.
"while" loop is the alternative to for loop.
With while loop you only need to define the termination condition.
This exercise is a common and well-known exercise for every programming language:
Drawing some shapes with * character and combination of for loops.
In some specific cases you may need to end the execution of a for loop. In that case you use break statement.
Nested loops: Loop inside a loop
Nested loops are being used inside in most of the applications.
You can use a loop inside a loop or you may use them sequentially. Their boundaries might be completely independent from each other or their boundaries may change according to each other.
Learn to use nested loops to draw a bordered rectangle with stars, adjusting loop boundaries by iteration and making the size dynamic with a rectangle maker class.
•You may initialize the array upon the allocation of memory with this syntax:
•int x [] = new int[] {1,-1,9,0,5};
•We can use for and while loops to traverse a loop. Length of an array can be accessed by length attribute of array.
int myGreatArray[] = new int[10];
for(int i = 0; i < myGreatArray.length; i++){
System.out.println(myGreatArray[i]);
}
All tabular data can be represented as arrays of arrays. They are called as multi-dimensional array.
Board games like chess, match-results table of a football league, sales data over months, seat plan of a bus...
Every row means a separate array.
Bicycle: Is an object with two tiers, paddles and a seat.
Human: Is an object with a torso, two legs, two arms, a head and speaking, thinking behaviors.
Love: Is an object between two human that can last forever or may end quickly.
Instance is the real object with flesh and blood, allocating some memory to store its individual values.
For creating an instance in Java, "new" keyword is used. When you create an instance enough memory is allocated in JVM and starting address of the instance returns a reference.
§ If you define a return type, you must return a value of this type.
§ If return type is void, there is no need to return a value. If so, you can not return.
§ After returning a value, you can not execute any statement.
§ All flows execution must return a value.
§ You may return only one value.
Class is a meta-data (definition) of a real world object and the heart of object oriented programming. It is above all methods, behaviors contrary to functional programming or declarative programming. Thus, before coding some code flow, you need to design a class to store some state inside an object (instance). That is why no code may exist outside of a class. So does it make sense to put main method into a class? It should from now on. You can create a class with class keyword in a separate file and define some attributes and methods inside it. You can create concrete objects with new keyword. As soon as you create an instance and allocate some memory for it, you will be able to store state of this object. State is the snapshot of an object at current time and can be modified either directly or via methods indirectly. Both methods and attributes can be accessed by dot notation on any object. (instance)
A method mostly returns a value.
(If return value is void, there is no need to return a value) return keyword completes the execution of the current method so that none of the below lines inside the method are executed.
If the return type of the method is not void, than all of the execution flows must return a value.
Methods with same name may exist in the same class if their argument lists are different.
These methods are called as overloaded versions of each other.
int sum(int v1, int v2)
int sum(int v1, int v2, int v3)
int sum(int v1, int v2, int v3, int v4)
String concatanateStrings(String[] values);
String concatanateStrings(String… values)
Constructor is a special method that
Constructor eases to set instance variables without writing explicit lines to set them.
So far, we have dealt with readdressable (variable) values that created at run-time (while the execution of the program). They are called as «Dynamic variables» When you create a new instance of a class, a brand new memory is allocated in heap space. Instance context isolates different instance’s values and method executions from each other.
Java has another context called «static».
Static context: Before the execution of the program (on class loading phase), variables are stored into class space and the address does not change throughout the execution
Java application can not interfere with a memory block outside the JVM.
Method execution order is done inside stack space.
When a method is called, method-specific data is collected, tied together and put into stack space. It is removed when the execution is done.
You will learn the details of stack space. If you know the stack space in theory, dealing with references and instances will be easier.
Stack space is limited. Here, without popping a stack frame from the stack, a new one is pushed. So allocated memory for method information grows rapidly.
JVM throws a StackOverflowException and halts the execution.
Different references to the same object throughout the application refer to the very same memory address. In this case one of the references modifies the object, all other references will be aware of that modification.
This is not valid for primitive values. Next lecture will demonstrate that fact.
Since primitives are stored in stack instead of heap space, references from different method contexts will use the copy of the values. So modification of the value on a reference will not be reflected to other references.
Learn to find the longest winning streak in a boolean array by iterating, tracking start and end indices, comparing lengths, and handling boundary checks.
Object oriented programming means that any value or behaviour must be attached to a class that corresponds to an entity in real world.
It is a professional approach in software programming supplies:
•Modularity
•Extensibility
•Reausability
This is called as composition.
•Data encapsulation hides critical data of a class (entity) from other classes by preventing access with access modifiers.
•Because some data is internal and critical data of an object.
•The attributes might be in a specific range, specific proportion with each other or they should not be assigned some specific values to work properly.
String is used for storing texts in Java programs.
String is composed of a character array implicitly and some utiliyt methods.
String equality is done by equals() method.
Never ever use == for comparing strings.
Watch the lecture and see the details.
String methods:
length(): Returns how many characters inside
charAt(): Returns the character at any index
indexOf() : Searches for a character or string inside this string
substring(): Returns the desired part of the string
split(): Splits the method from a desired character and put the splitted strings into a String array
replace(): Replace a word or character with a given string or character.
toLowerCase(): Converts all the characters into lower case.
toUpperCase(): Converts all the characters into upper case.
contains(): Checks if a string exists in this string.
You will learn using overloaded versions of indexOf() method.
indexOf() method in String has some overloaded versions to configure the index where to start. This is used to count words in a string. Search will be case sensitive. Method is: indexOf(int startIndex)
You will learn
Learn how to remove all occurrences of a word from a sentence in Java using indexOf, substring, and a static method, with attention to case sensitivity and index handling.
indexOf(): finds another string in the current string
split(): splits the string according to a given string and returns the parts as a string array
toUpperCase(): converts all the letters inside a string to lowercase toLowerCase(): converts all the letters inside a string to uppercase.
We construct some template with some special markers search for a string snippet that matched that template.
•This special markers are called as regular expressions.
•Regular expressions are used to
•Determine if a string matches a given template (email address, URL)
•All the substrings of this string matches a given template.
Found result can be used to count the occurrences, replace them with another string.
Two exercises will be done:
Which ones below are real email address? Write a regular expression to decide if each one is a valid email address or not.
btocakci@
•btocakci@d
•talha ocakci@gmail.com
•btocakci@@
•TALHAOCAKCI@gmail.com
•btocakci@@yahoo.com
•btocakciatgmail.com
•talha.ocakci@gmail.com
•talha_ocakci@gmail.c.uk
•talha_ocakci@gmail.co.uk
•talha-ocakci@gmail.com.tr
•talhaocakci65@gmail.com
•talha_ocakci@gmail.co.45
•talha@45.net.tr
You will learn how to parse a url into its elements. For instance
https://www.udemy.com/java-8-core-training-/learn/?instructorPreviewMode=student#/lecture/3699776
will be parsed to:
domain: udemy.com
protocol: https
course url: java-8-core-training-
internal url: learn/?instructorPreviewMode=student#/lecture/3699776
Primitives are the exceptional type of an object oriented language.
They need to be wrapped into a class in some cases to be used as objects.
For converting a primitive to an object, we use wrapper classes. They are Integer, Float, Double, Character, Long, Short, Boolean
java.util.Date: Simple class to represent a given time.
Used for simple time comparisons and string-time conversions
•Done with SimpleDateFormat class.
•This class may convert a String to Date and vice versa.
•Format is something like dd/MM/yyyy hh:mm:ss
•Much more complex class than java.util.Date.
•Have ability to manipulate date and time
•Have ability to see so much detail of the date inside.
•Have ability to change locale and timezone.
How to convert
Write a method that gets two dates as String and calculate the difference and then write the difference in a format such as "3 days 10 hours 2 minutes 39 seconds".
We are developing a training calendar for a runner. Runner must go for a measurement session in a hospital once in 10 day. If the 10th day is Sunday, the day must be postponed to Monday. Print next 4 measurement days assuming that today is 05 August 2016.
Create a class Training and add “public static void printDates(String today, int interval)” method. Do the following in this method:
Learn how to use BigDecimal to avoid precision loss in Java, perform operations like subtract and multiply, compare values, and format results with scale and toPlainString.
Discover how string immutability makes concatenation costly and how a string buffer boosts performance by appending content and converting to a single string.
NEW: ONLINE CODE PRACTICES ARE ADDED. YOU STUMBLED UPON THE FIRST JAVA COURSE WITH UDEMY ONLINE CODE PRACTICES.
Read the problem, write your code and get the feedback automatically. That's it!
[ALL SOURCE CODE IN THE FIRST LECTURE. JUST IMPORT AND TEST!!!]
[FIRST STEP TO PREPARATION FOR THE ORACLE CERTIFICATION EXAMS: OCJA and OCJP]
[MOST CHAPTERS HAVE A GREAT EXERCISE AND ITS SOLUTION IN DETAILS]
This course is for those want to be a Java programmer by following a proven methodology and one-to-one online version of the lectures I gave to hundreds of students in several classrooms in several high-quality training center.
The biggest missing part for programming students is the exercises that they may work on. This class has high-quality exercises and their solutions right after the video explanations.
Here is our agenda:
0- Why java? What is platform independency? Why it is the most used programming language in professional software development?
1- Learn programming basics:
Using variables, primitive types, mathematical and logical operators.
Control structures, loops and really high-quality exercises to have hands-on experience.
2- Learn one dimensional and multidimensional arrays:
Use this basic data collection and use them inside real-world, fun practices. Find the longest lost series of an NBA team for instance :)
3- Learn object oriented programming:
Learn encapsulation, inheritance, abstraction with great examples and exercises. Possibly you wasted lots of time by watching similar unclear explanations so far. It is time to polish the dust of these concepts.
4- Learn core types and great utility classes of Java.
How a professional programmer leverages built-in types and utility classes in real life? StringBuilder, StringBuffer, Date type, String - Date conversions with SimpleDateFormat, Math class, Collections and Arrays class the topics you will learn.
5- Learn regular expressions.
Extracting useful data from a string by regular expressions is the greatest feature of all programming languages. But it is the most overlooked one. We don't overlook it. With two great explanation you will learn how to extract data from a URL and you will validate an email address ( by not Googling and copying of course!!!)
6- Learn data collections.
Everyone teaches you what is a list, set and map. How to put data and retrieve it. But this is the top of the iceberg. You MUST know where to use them, when to leverage the collections. Included exercises are asked in job interviews!!! Hold tight!!!
7- Learn file operations
How java communicates with files, read text files, binary files or write to them? How the content of the file is processed with data collections? You will learn by great exercises.
At this point you may move on Java EE course for further understanding.
8- Functional programming in Java 8
Using ASM interfaces, Function, Predicate, Consumer, Supplier interfaces, lambda expressions.
Using streams to process collections in functional style.
Leveraging multi-cpu cores easily by using parallel streams
9- Java 8 Date and Time API
10- Generics
11- Java and Database Interaction with MySQL
Have a great experience!!!