Learn Java in One Video - 15-minute Crash Course
Summary
TLDRIn this informative video, John, a seasoned Java programmer, empathizes with beginners' struggles and shares his journey from confusion to expertise. He guides viewers through setting up an IDE, writing basic Java programs, understanding variables, and utilizing methods. John introduces object-oriented programming concepts, explaining classes, objects, and static vs. non-static methods. His aim is to simplify Java, offering a comprehensive course for deeper insights and encouraging questions for further assistance.
Takeaways
- 😀 The speaker empathizes with those struggling to learn Java, emphasizing that it's a common experience and not to feel alone.
- 📚 The speaker introduces himself as John, a seasoned Java programmer who aims to share knowledge in an understandable way.
- 💻 It's necessary to install an IDE (Integrated Development Environment) like Eclipse to write Java programs more efficiently.
- 🛠️ Eclipse is used to write Java programs and automatically translate them into bytecode, a format the computer can understand.
- 📝 The process of creating a Java program in Eclipse involves creating a new project and class, with the main method being the starting point for code execution.
- 🔢 Variables in Java are used to store data and consist of a name, type, and value, with 'int' being an example of a primitive type.
- 📑 The 'main' method is where most of the coding happens, and the code within its curly brackets defines what the program does when run.
- 🔠 Java has eight primitive types, including 'int' for integers, 'double' for decimal numbers, and 'char' for characters.
- 🔑 Non-primitive types like 'String' are used to hold text and offer various methods for manipulation, such as 'length()' and 'toUpperCase()'.
- 🔄 Methods in Java can be created by the programmer to bundle functionality and avoid code repetition, and can take parameters and return values.
- 🔒 Conditional statements like 'if-else' allow for decision-making in programs based on conditions, using '==' for equality checks.
- 🔁 Loops, such as 'for' loops, enable repeated execution of code segments, with the loop's condition controlling the number of iterations.
- 🐱 Java is object-oriented, allowing for the creation of classes as blueprints for objects, which can have attributes and behaviors defined by the class.
- 📌 The 'static' keyword in Java methods means they can be called without creating an object instance, while non-static methods require an object.
Q & A
What does the speaker struggle with in the beginning of the script?
-The speaker struggled with understanding basic concepts of Java and felt overwhelmed in their first Java class in college.
What is the purpose of an Integrated Development Environment (IDE)?
-An IDE is a program that makes it easier to write code, similar to how Microsoft Word makes it easier to write school papers.
What is the name of the IDE used by the speaker in the video?
-The speaker is using an IDE called Eclipse.
What does the speaker suggest to install before starting to code in Java?
-The speaker suggests installing an IDE and possibly other tools, mentioning that the process is super easy and only takes a few minutes.
How does the speaker describe the process of creating a new Java project in Eclipse?
-The speaker describes creating a new Java project by right-clicking in the Package Explorer, selecting 'New Java Project', giving it a name, and clicking 'Finish'.
What is a 'class' in Java according to the script?
-A 'class' in Java is essentially a Java file, which is a fancy name for a container of code and functionality.
What is the significance of the 'main' method in Java?
-The 'main' method is significant because it is the entry point of a Java program, containing the code that runs when the program is executed.
What is a variable in Java and what are its components?
-A variable in Java is used to store data and has three components: a name, a type, and a value.
What is the difference between primitive and non-primitive types in Java?
-Primitive types are the most basic types in Java, indicated by a lowercase letter, such as 'int' for integers. Non-primitive types are built on top of these and include more complex structures like 'String'.
How can you interact with a non-primitive type like 'String' in Java?
-You can interact with a non-primitive type like 'String' by calling its methods, such as 'length()' to find the length of the string or 'toUpperCase()' to convert the string to uppercase.
What is a method in Java and how is it used?
-A method in Java is a block of code that performs a specific task. It is used by declaring the method with a name and then calling it by that name within the code, potentially with parameters and a return type if necessary.
What is the role of 'static' in methods and classes in Java?
-The 'static' keyword in Java means that the method or class can be called without creating an instance of the class. It is associated with the class itself rather than instances of the class.
How does the speaker explain the concept of object-oriented programming in Java?
-The speaker explains that object-oriented programming in Java involves creating classes as blueprints for objects, which can then be instantiated with specific attributes and behaviors.
What is the purpose of conditional statements in Java?
-Conditional statements in Java are used to perform different actions based on whether certain conditions are true or false, using 'if', 'else if', and 'else' clauses.
How are loops used in Java to repeat code execution?
-Loops in Java, such as 'for' loops, are used to repeat code execution multiple times without copying and pasting the same code. They are controlled by initializing a variable, a condition to continue the loop, and an increment or decrement operation.
What is the speaker's final recommendation for those interested in learning more about Java?
-The speaker recommends a full Java course available in the description of the video for those who want to go into more depth on various topics of Java.
Outlines
📚 Java Learning and Setup Essentials
The speaker empathizes with the struggles of learning Java, sharing personal experiences and offering help. The paragraph introduces the speaker, John, who has been programming in Java for 10 years and plans to share knowledge in an understandable way. It covers the basics of setting up Java development, including installing an IDE like Eclipse, which simplifies the coding process. The video also guides viewers on creating a Java project and class in Eclipse, explaining the significance of the 'main method' and how to write a simple program that prints variable values. The importance of variables, their types, and values are discussed, along with how to perform operations like multiplication and store results in new variables.
🔍 Exploring Variables, Methods, and Conditional Logic in Java
This section delves deeper into Java variables, explaining primitive types like 'int', 'double', and 'char', and their usage. It demonstrates variable interaction through example calculations and the assignment of results to new variables. The paragraph introduces non-primitive types, particularly 'String', and discusses methods associated with them, such as 'length' and 'toUpperCase'. The concept of creating custom methods in Java is introduced, explaining how methods can be used to avoid code repetition and can take parameters and return values. Conditional statements and loops, such as 'if', 'else', and 'for', are also explained, showing how they can be used to control program flow based on conditions and repeat code execution.
🐱 Object-Oriented Programming with Java Classes and Objects
The final paragraph introduces the core concept of object-oriented programming in Java, focusing on classes and objects. It explains how to create a separate class, such as 'Cat', and use it as a blueprint to create objects with unique attributes and behaviors. The paragraph demonstrates creating class methods, both static and non-static, and the difference between them in terms of accessibility and usage. It also illustrates how to set and use properties of objects, like name and age, and calls methods on them. The video aims to clarify the use of 'static' in methods and the overall object-oriented approach to structuring Java programs, offering a foundation for more complex Java applications.
Mindmap
Keywords
💡Java
💡IDE (Integrated Development Environment)
💡Variables
💡Main Method
💡Primitive Types
💡String
💡Methods
💡Conditional Statements
💡Loops
💡Object-Oriented Programming (OOP)
💡Static
Highlights
The speaker empathizes with those struggling to learn Java, emphasizing that they are not alone.
John, the speaker, shares his personal experience of struggling with Java in college but now has 10 years of experience.
The importance of installing an IDE like Eclipse for writing Java programs is discussed.
Eclipse is introduced as the IDE used for writing and translating Java programs into bytecode.
A step-by-step guide on creating a Java project and class in Eclipse is provided.
Explanation of the 'main method' in Java and its role in running a program.
Introduction to variables, their types, and values in Java with examples.
The concept of primitive types in Java and their characteristics is explained.
Demonstration of how to perform operations like multiplication on variables and store results.
Introduction to non-primitive types like 'String' and their usage in Java.
Explanation of methods, how to call them, and their functionality in Java.
The process of creating custom methods in Java and their purpose is outlined.
Parameters and return values in methods are introduced with examples.
Conditional statements and their syntax in Java are explained with examples.
The concept of loops, specifically 'for loops', and their use in Java is discussed.
Java's object-oriented programming nature and the use of classes as blueprints for objects.
Creating objects from classes and setting their attributes like name and age.
The difference between static and non-static methods in Java and their usage.
John offers further help for any Java questions in the comments and provides a link to a full Java course.
Transcripts
if you're struggling learning java i
understand how you're feeling it can
feel like everyone around you is some
kind of programming genius who just gets
everything with no problem at all and
you feel like you must be the only one
having trouble with it you're absolutely
not alone and you're in the right place
i remember in my first java class in
college i really struggled to understand
some of just the basic concepts and
really just felt overwhelmed but now
i've been programming in java for a
living for the past 10 years and i want
to make sure you don't have to struggle
the same way i did my name's john and i
love sharing what i've learned about
java in a clear and understandable way
so please consider subscribing if you'd
like to see more helpful java videos in
this video we'll go over everything you
need to know to get started writing
great java programs before you can code
anything in java there's a couple of
things you have to have installed if
you've already done that awesome and if
not it's super easy it just takes a few
minutes i have a video here going
through the whole process one of the
things you'll want to install is called
an ide and integrated development
environment and that's what i have open
here the name sounds really complicated
but it's basically just a program that
makes it easier to write code kind of
like microsoft word makes it easier to
write school papers here the ide that
i'm using is called eclipse basically
we're going to write our java programs
here in eclipse and then it is going to
take our programs and automatically
translate them into a format the
computer can understand something called
byte code you know essentially the ones
and zeros that make the computer happy
and it's going to run it when you open
eclipse to get started creating a java
program just right click here in this
area called uh the package explorer and
go to new java project you can give it
whatever name you want we'll just call
it a project pineapple you can uncheck
this module thing down here we don't
need that and click finish you can see
it created our project for us here
project pineapple then you can expand
this drop down and right click this src
folder here which stands for source and
go to new class a class is basically
just a fancy name for a java file give
that name to whatever you want like
awesome java program and you want to
check this box down here that says
public static void main string args
we'll talk a little more about what that
means later then click finish and then
eclipse will automatically generate this
kind of framework for a working java
program for you now all of these
programming looking terms and keywords
might feel really intimidating but
really all this is saying is hey java
i've got this new program called awesome
java program and when i tell you to run
here's all the stuff that i want you to
do this whole section here is what we
call the main method and all the
commands we put in between these two
curly brackets in the main method are
what it's going to do when we tell it to
run so that's where we're going to be
writing most of our code this line here
with the two slashes is just an
automatically generated thing that we
don't need so we can just get rid of it
just about everything we'll do in java
revolves around creating and using
things called variables variables are
just used to store data so here's an
example and myint equals seven now
variables have a name a type and a value
for this variable int is the type it
stands for integer int is basically just
a number this my int is the name of the
variable we can give it whatever name we
want and this equals seven here is
giving this my into the value of seven
so this just says hey java i have a
number here i want to call it myant and
please give it the value of seven to
start out with and then we have this
semicolon in java most lines will end
with a semicolon it's just telling java
that's the end of the statement now
anywhere after that line in our program
we can get the value stored in that
variable just by using its name for
example if we want to just print it out
the command to print something out in
java is system.out.println
and in parentheses we specify the name
of that variable myant and we end with a
semicolon and we can click save and then
click run to run our program and we see
our output of the program here in our
console so it just prints out the value
of this my int variable which is seven
int isn't the only type of variable we
can create for example if you want to
create a decimal number you can use
double let's say we want to make a shoe
size double shoe size equals 9.5 if you
want to store a character you can use
the char type char my initial equals j
that'll be in single quotes a lot of the
magic encoding happens when we take
these variables and have them interact
with each other so we can take this
mayan variable and multiply it by the
shoe size if we want in java to multiply
you just use star so my int times shoe
size save and run it we see that we get
the result 66.5 which is 7 times 9.5 and
also instead of just printing out that
result you can actually store the result
of that calculation in another variable
so we can say double result equals my
int times shoe size all of these types
so far and double and char those are
called primitive types in java there are
eight primitive types total in java and
i have a video going over all of them
and how to use them in detail here
primitives are like the absolute basic
types in java like the sticks and stones
you'll know it's a primitive type in
java if it starts with a lowercase
letter every other type you use in java
is built on top of these primitive types
but there are tons of other types you
can use and you can even create your own
like we'll see later probably the
non-primitive type that you're going to
use most is called string string
variables are used to hold text string
my name equals john for strings you put
them in double quotes instead of single
quotes you can tell that string is not a
primitive type because it starts with a
capital s and also the primitive types
have a different coloring in eclipse
than other types do when you create a
non-primitive variable like this there's
also even more stuff you can do with it
that can be different for each type to
see what you can do with the variable if
you're using a fancy ide like eclipse
you can start out by just typing the
variable name then type a period and
you'll immediately see all the cool
things you can do with this variable
these are all called methods and when we
use any of them it's called calling a
method as you're scrolling through these
you can click one and you'll get a
description of what that method does for
example this length method says it
returns the length of this string and if
we want to use it we just double click
it or you can also just type it out if
you want to so if we move this down here
so we can print out the result of this
method call it prints out four because
john the value of the my name variable
is four characters long but there are a
ton of other methods available like for
example there's one called a two
uppercase and if we use that it gives
you an all uppercase version of that
string and if you already have the
method out here in your code and you
want to remind yourself what it does you
can just hover over the method name and
a little pop-up will appear with the
description one thing you can't do is
you can't call a method on a primitive
variable like my interior if i try to do
my int dot nothing pops up it just
doesn't work speaking of methods you can
also create your own to create a new
method here in the same java file i'll
type it out first and then we'll talk a
bit about what it means private static
void burp this whole line here is called
the method declaration and this part
right here before the parentheses is the
name of the method here we called it
burp and any code that we put between
these two curly brackets is what it's
going to do when this method is called
let's just have it print out
burp but if we go ahead and save and run
our code now nothing happens nothing's
printed out why is that that's because
if you remember when we run our java
program java just runs everything that
we put inside our main method and right
now there's nothing in here that calls
this other method that we created so
let's change that now if we want to call
this method all we have to do is use its
name burp and we also need an open and
close parentheses whenever you see this
open and close parentheses you'll know
that it's a method being called now if
we save and run our program successfully
burps so now we can have our program
burp whenever we want just by calling
burp of course a method can be a whole
lot more complicated than this and a big
reason to make a method is because you
might have a whole big complicated chunk
of code that you don't want to repeat
package it up in a method and you can
just call it as many times you want from
anywhere in your code just by using its
name now a method can also take what is
called parameters so for example if this
method was called print name between
these two parentheses is where you would
put the parameters let's say it had a
string parameter that was called name
and then just printed out my name is
plus name this plus is how you link two
strings together in java that's called
concatenating strings but now when you
call this print name method you have to
pass in a value for that name parameter
and you pass in that value by putting it
between these two parentheses uh john
and we can run it and see that it prints
out my name is john you can even take
multiple parameters if you want just
separate them by commas so i can also
take in like int number and when you're
calling it you just do the same thing
you just separate the values that you're
passing in with a comma if you want you
can also have your method return a value
right here in the method declaration
where we have this void void means it's
not returning any values but if you want
it to return a value this is where we
specify the type of the thing that it's
going to return so if we want it to
return a string we can just change this
to a string but now we have to actually
return a string somewhere in our method
so what we can do instead of just
printing out my name is blah we can just
change this to return
that value my name is blah the code that
calls this can do whatever it wants with
the string that's returned for example
we could just print it out ourselves
here or if we want since this returns a
string we can actually save that
resulting value in our own string
variable so string name equals the
result of this method call one of the
most useful things you'll ever use in
java is called conditional statements
that's your basic if this then that
conditional statements in java will look
like this if whatever condition we put
in here is true run this stuff otherwise
if whatever condition we put in here is
true run this stuff and if neither one
of those are the case run this and you
don't necessarily need all three pieces
for this you might just have an if you
might just have an if else you don't
need all three so what kind of
conditions can we have in here so we
could say like if name equals john then
print this guy is awesome else if the
name equals larry this guy is okay i
guess and if it's not john and not larry
prince i don't know this guy at all this
example uses strings as its conditions
but if you want to use the like a number
as the condition you can do things like
if number
double equals five in java you use
double equal to check equality like this
that's because the single equals is
already being used for assigning values
to variables so just remember to use
double equals but with numbers you don't
always just have to check for equals you
can do other things like if the number
is greater than 5 or less than 5 or if
you want to say if the number is not
equal to 5 you use exclamation point
equals next if you want to be able to
repeat a piece of code a whole bunch of
times without actually copying and
pasting the same code over and over and
over again you can use what's called a
loop one type of loop in java is a for
loop and it looks like this and i equals
0 i less than 10 i plus plus what this
will do is run everything inside these
curly brackets 10 times how it does that
is it declares this variable i and says
hey keep looping while i is less than
10. and every time it goes through the
loop increment i by one that's what this
i plus plus does so we can have it print
out these pretzels are making me thirsty
if we run it it'll print out these
pretzels are making me thirsty 10 times
and we can have this for loop do this
however many times we want so if we
change this 10 to a thousand and run our
program it'll print it out a thousand
times one huge thing about java is that
it's an object oriented programming
language a big part of being object
oriented is that you can take a whole
bunch of code and put it in another java
file called a class and you can use that
code in some other java file like your
main file so let's do that now we can go
over and right click on source again and
go to new class say we want to create a
cat class so we'll call it cat and you
can create a method in your class like
this public static void ding dong which
prints out ding dong this public keyword
here makes it so this method can be
called from any other java file if you
remember in our other method we used
private private makes it so this method
can only be called from within this file
that was fine because that's all we
needed it for but if you make it public
it can be used anywhere so now we can
call this cat ding dong method from our
main program like this we just say cat
dot ding dong so you can absolutely use
a separate class just like this a place
to put other methods so they don't
clutter up your main class but the main
use of a separate class like this is
actually as a blueprint to create what
are called objects so here we have a cat
class now this class itself isn't a cat
object but we can use this class to
create cat objects as many as we want
and here's how so back in our main
program we can just say cat i cat equals
new cat this creates a brand new cat
object and stores it in this variable my
cat and we can create another one if we
want so cat
another cat equals new cat right now we
haven't really put much of anything in
this cat class so our individual cats
that we've created from it can't really
do a whole lot but we can change that so
we know a cat in real life probably has
a name and an age and it can meow right
we can make our cat class like that too
so that the cats we create can do those
things so here's how we do that we just
add string name int age and we'll create
a new method public void meow that
prints meow now note that we didn't
actually set a value for the name or the
age here remember the class isn't a cat
in itself it's a blueprint for creating
cats and it tells you what kind of
attributes it has and what it can do so
what this is saying is that each
individual cat made from this class can
have a name it can have an age and it
can do this thing it can meow and back
here where we're actually creating our
individual cats that's when we can
actually set the name and age of these
individual cats my cat dot name equals
fred my cat.age equals six we use this
dot to access the fields on these
objects very similarly to how we call
methods but you'll know the difference
because when we call methods we always
have an open and close parentheses and
when we're accessing a field on that
class like name or age we don't have any
parentheses and on another cat a whole
separate cat object we can set its own
values so another cat.name equals stella
stella's age is five later on in our
program we can get those values and do
whatever we want with them so if we want
to print out fred's age later we can do
that icat dot age and it prints out six
one huge point of confusion for me
personally when i was learning java is
this whole static thing you might have
noticed in our methods sometimes we use
this static keyword and sometimes we
didn't all this static keyword means is
that this method can be called without
using an individual cat object for
example we made this ding dong method
static so back here in our main method
we could just call cat dot ding dong
notice we're just calling this method on
the clasp itself not on any specific cat
object that we created we don't need to
create a cat object first if we just
want to use this method but if it's not
static like this meow method you can
only call that method using an
individual cat object so back here
notice that i can't call
hat.meow just using the class name it
gives me an error that says i can't make
a static reference to this non-static
method but down here where i've actually
created a cat object like my cat i can
call meow on that just fine whether a
certain method that you make is static
or non-static just depends on what makes
sense for what you're trying to do of
course java is much deeper than what can
be covered in one video like this but
this should give you a ton of tools that
you can use and build off of to start
making some awesome programs i do have a
full java course available in a link
down in the description if you're
interested that goes way more into depth
on a ton of topics but if not that's
awesome too i'm just thrilled to have
you here with me my goal is really just
to help as many people as i possibly can
for real if you ever have any sort of
java questions that i might be able to
help with just put them in the comments
and i'll do my best to respond thanks so
much for watching i'm so glad to have
you here with me and i'll see you in the
next video
Weitere ähnliche Videos ansehen
Packages in Java
Object-Oriented programming Course Intro
Learn Java in 14 Minutes (seriously)
20 Basic Core Java Interview Questions & Answers- TCS, Accenture, Cognizant, Infosys, Wipro, HCL
Belajar Java [OOP] - 16 - Hierarki Package (default, public, static)
Upcasting and Downcasting in Java - Full Tutorial
5.0 / 5 (0 votes)