Showing posts with label Methods. Show all posts
Showing posts with label Methods. Show all posts
Use constants rather than numbers - declaring variables with FINAL statement
Suppose the government hired you to create an application that, among other things, examines whether a citizen is adulthood or not.
How would you do this conditional test?
if (age> = 21) or who knows ... if (age > 20)?
Both correct, but absolutely not recommended.
In this article we will teach an important lesson in Java: Do not use numbers, but constant.
Java Video Lesson: Constructors
This video is from the New Boston project: http://thenewboston.org/ , made by Bucky Roberts.
We just find the best Java video lesson for your.
In this video tutorial, Buckey will teach us more about the constructors methods in Java.
We already explained about Default constructor and with parameters: what they are, what they are for and how to use
Marcadores:
Methods,
Video lessons
set and get: what they are and how to use these methods correctly
We will learn this lesson of our online Java course the two methods most commonly used by Java programmers: the getters and setters.
Marcadores:
Methods,
Object Oriented
Self-reference with this and How to invoking Classes and Objects methods
In the last tutorial related to Java Object Orientation, we talked about creating constructors, with or without parameters, in our classes.
In this small class, we will learn how to reference members of an object through the keyword 'this', which is a tool widely used by programmers in Java methods within classes.
In this small class, we will learn how to reference members of an object through the keyword 'this', which is a tool widely used by programmers in Java methods within classes.
Marcadores:
Commands,
Methods,
Object Oriented
Default constructor and with parameters: what they are, what they are for and how to use
Have you noticed that in the last tutorial on how to declare and create class and instantiate objects, we did:
Student student = new Student ();
You noticed how repeated 'Student' twice?
Why? It is pointless or a waste of time to repeat it?
In Java - indeed, in programming - everything has a reason.
In this article you will learn about the constructors and know the reason for the repetition and how to use the methods constructors.
Student student = new Student ();
You noticed how repeated 'Student' twice?
Why? It is pointless or a waste of time to repeat it?
In Java - indeed, in programming - everything has a reason.
In this article you will learn about the constructors and know the reason for the repetition and how to use the methods constructors.
Marcadores:
Methods,
Object Oriented
Exercise: Method that receives any number of arguments (...)
Solved and commented Java exercise:
A teacher, very cool, did 3 tests during a semester but will only take into account the two highest grades to average.
Write a Java application that asks the value of 3 notes, show how it would mean to these 3 tests, average with the 2 highest grades, as well as his highest score and your lowest note. These averages must be calculated using the same method, because you're a Java programmer and will not create a lot of methods for nothing.
Create another method that receives all 3 grades and returns the largest. And another that returns the smallest.
Varargs - passing a list of arguments, of any size, to a method
So far, in our Java course, always specify the exact number of arguments that a method must receive.
When we will study Arrays and ArrayLists - soon , we should see that we can pass any number of values to the methods.
But there is another way to do this in Java, using the ellipsis: ...
Using this, we can move one, two, three or any number of arguments to a method that it will know how to handle this data.
How to make a Tic Tac Toe (noughts and crosses) game in Java
It's time to put our knowledge into practice to do something really cool and useful:The Tic Tac Toe game in Java! Also known as noughts and crosses!
This is a simple version, to be played with two people. Note that in a simple Java application like this, the result came out around 300 lines of code.
If you are Java programmer, click to see the full commented code and explanation about the Tic Tac Toe Java Game creation.
Yes, there is a strategy we can adopt (or the computer may adopt) to never lose a game of tic tac toe:
http://en.wikipedia.org/wiki/Tic-tac-toe
Graphical Application: shows the roots of a quadratic equation in Java
Java exercise using Dialog Box:
Write a program that receives the coefficients of a quadratic equation and returns its roots, even complex ones, through dialog boxes.
Write a program that receives the coefficients of a quadratic equation and returns its roots, even complex ones, through dialog boxes.
Marcadores:
Apps,
Graphic Programming,
Methods
How to pass variables of type String to int, float and double
In the past two articles we learned how to display messages and receive data from the dialogs box.
However, we note that the dialogs see everything as String type.
We will teach now, in our Java course how to transform what was typed as string to integer, float, double ...
Marcadores:
Classes,
Graphic Programming,
Methods
Getting user data through dialogs boxes
We saw in the last article that the dialog boxes are very used to display messages (mainly for errors and alerts), and show how to do this in Java.However, it can also be used (and we show how to do this) to receive data from the user by an interface more friendly and graphical :)
Marcadores:
Classes,
Graphic Programming,
Methods
Exercises involving methods
Feel free to practice your creativity, using what ever you learned you want (while, for, do ... while) commands (switch, break and continue), if else conditionals tests or even nothing ;)However, as we are in the methods section, it is important to train and use methods, the return statement, and parameters and arguments on all issues below:
Method overloading: declaring methods with the same name
+em+Java.jpg)
In our article about parameters and arguments in Java, we show an example of a method that takes a number and returns the square of that number.
But this method has a limitation: it only received integers.
And if you want to create methods with float? double?
Make an overload.
Marcadores:
Methods
Game: Guess the number raffled by the computer
Play a game is very good and fun... but playing a game that you have created, is a pleasure that just a few have.The Java programming language is known to be widely used for creating games. Most likely you've played a game, even online ones, are done in Java.
Based on the knowledge gained in our online course of Java, it is possible to create a game.
Although very simple, it is quite genious and cool.
The computer will randomly select a number between 1 and 1000 and you have to guess what number this is.
Each round you enter a number and the computer will give you the tips, saying the number you typed is greater or less than the number it choose.
Ends when you hit, and he keeps the number of attempts you made. Can you beat your own record?
You know what's the best strategy?
Marcadores:
Classes,
Flux Control,
Games,
Methods,
Statements
Math Class: constants, main methods and calling methods from other classes
Let us study an important class, the Math Class, which comes several mathematical functions that will help us greatly in our complete an free Java course.Allied to this large and powerful class with our Methods section, we'll learn how to use the methods that are declared in a different class that we're making the call.
Parameters and Arguments: passing information for methods
In our Java course, so far, our methods were very specific things, such as displaying a string, a menu or performed mathematical calculations.
Therefore, in practice, is not very useful.
Therefore, in practice, is not very useful.
Marcadores:
Methods
App: Simple menu using methods, loops and switch
Using a method to display a menu of options
Focusing on the goal of our Java course, and show that it is doing useful things, we show a utility method that simply display messages on the screen.
Marcadores:
Apps,
Methods,
Statements
The return statement:obtaining information from methods
In this section of Progressive Java course will show you how to use the serve and return statement in methods.Methods learn how to use and declare methods in Java
Methods in Java
01. The return statement:obtaining information from methods
1.1 App: Simple menu using methods, loops and switch
02. Parameters and Arguments: passing information for methods
03. Math Class: constants, main methods and calling methods from other classes
Game: Guess the number raffled by the computer
04. Method overloading: declaring methods with the same name
05. Varargs - passing a list of arguments, of any size, to a method
06. Exercises involving the use of Methods
1.1 App: Simple menu using methods, loops and switch
02. Parameters and Arguments: passing information for methods
03. Math Class: constants, main methods and calling methods from other classes
Game: Guess the number raffled by the computer
04. Method overloading: declaring methods with the same name
05. Varargs - passing a list of arguments, of any size, to a method
06. Exercises involving the use of Methods
Marcadores:
Methods
Methods: Introduction, what they are, what they are for, how and when to use methods
To have a section in our Progressive Java course, you should suspect the importance of methods.
In this article, we give a description of what methods are, what they are for, how to declare, how to use and when to use.
In this article, we give a description of what methods are, what they are for, how to declare, how to use and when to use.
Marcadores:
Methods
Subscribe to:
Posts (Atom)
