Monday, August 31, 2015

Set and get Methods in java.

Hello ,

we're gonna talk about how to set variables in work classes and set and get methods.

we're gonna talk briefly then show an example.

You won't get a job working with java if you set your variables public. So we need to set it private.

then how are we going to access it in other classes if its private?

we simply make 2 methods. First method is to allow us to set the variable.

The second method is to return it.



here is the example:-
import java.util.Scanner;

public class Fun {

public static void main(String args[]){

Scanner input = new Scanner(System.in);

milk object = new milk(); // creating an object from the class

System.out.println("enter a course name ");

String nameOfCourse = input.nextLine(); //recieving an input

object.setCourseName(nameOfCourse); // setting it

object.getCourseName(); // getting it and using it

System.out.println();

object.displayMessage(); // using the other method to display it


}

}


and we have to create that class "milk " in its seperate file but it has to get the extension such as " milk.java".

here's the class :-


public class milk {

private String courseName; // private variable






public void setCourseName(String x){ // accessing it

courseName = x;




}


public String getCourseName(){ // this method returns String data type

return courseName;



}


public void displayMessage(){ // displaying the msg

System.out.printf("welcome to %s", getCourseName());

}

} // end class



// thank you









// next we are going to talk about constructors




 

Sunday, August 30, 2015

hello every body, welcome to today's class.

we're going to discuss declaring a method wih a paramater in java programming language.

we're going to also use scanner class to get an input from user.

Small hints about the source code.

Line 12 creates a Scanner named input for reading the course name from the user. Line 15 creates the GradeBook object myGradeBook. Line 18 prompts the user to enter a course name. Line 19 reads the name from the user and assigns it to the nameOfCourse variable, using Scanner method nextLine to perform the input. The user types the course name and presses Enter to submit the course name to the program. Pressing Enter inserts a newline character at the end of the characters typed by the user. Method nextLine reads characters typed by the user until it encounters the newline character, then returns a String containing the characters up to, but not including, the newline. The newline character is discarded.

1 // GradeBook.java

2 // Class declaration with one method that has a parameter.

3

4 public class GradeBook

5 {

6 // display a welcome message to the GradeBook user

7 public void displayMessage(String coursename );

8 {

9 System.out.printf ("welcome to the grade book for %s", coursename);

10

11 } // end method displayMessage

12 } // end class GradeBook

Class declaration with one method that has a parameter.

1 // GradeBookTest.java

2 // Create GradeBook object and pass a String to

3 // its displayMessage method.

4 import java.util.Scanner; // program uses Scanner

5

6 public class GradeBookTest

7 {

8 // main method begins program execution

9 public static void main( String[] args )

10 {

11 // create Scanner to obtain input from command window

12 Scanner input = new Scanner( System.in );

13

14 // create a GradeBook object and assign it to myGradeBook

15 GradeBook myGradeBook = new GradeBook();

16

17 // prompt for and input course name

18 System.out.println( "Please enter the course name:" );

19 String nameOfCourse = input.nextLine(); // read a line of text

20 System.out.println(); // outputs a blank line

21

22 // call myGradeBook's displayMessage method

23 // and pass nameOfCourse as an argument

24 myGradeBook.displayMessage (nameOfCourse );

25 } // end main

26 } // end class GradeBookTest

that's all , thanks :D

































next we're gonna discuss set and get methods.

Saturday, August 29, 2015

If you become part of a development team in industry, you might work on applications that contain hundreds, or even thousands, of classes.


You can use Eclipse IDE which I recommend or any other IDE.


Obviously we won't be starting from scratch. There's always a introduction about computer languages and how the system works and how the java program works. You obviously can find these stuff in any java book. i would recommend you to download that book " java how to program".

Now, let's start!

You obviously going need a class to start a program. while you are writing a program, u gotta be careful that "java" is a case sensitive letters.

let's provide a small program and start illustrating it.

1

2 // Class declaration with one method.

3

4 public class GradeBook

5 {

6 // display a welcome message to the GradeBook user

7 public void displayMessage()

8 {

9 System.out.println( "Welcome to the Grade Book!" );

10 } // end method displayMessage

11 } // end class GradeBook


Class GradeBook (declared in the file GradeBook.java) will be used to display a message on the screen. welcoming the instructor to the grade book application.

Each classdeclaration that begins withkey word public must be stored in afile having the same name as the class and ending with the .java file-name extension.
Class GradeBook The GradeBook class declaration contains a displayMessage method (lines 7– 10) that displays a message on the screen. We’ll need to make an object of this class and call its method to execute line 9 and display the message. The class declaration begins in line 4. The keyword public is an access modifier. For now, we’ll simply declare every class public. Every class declaration contains keyword class followed immediately by the class’s name. Every class’s body is enclosed in a pair of left and right braces, as in lines 5 and 11 of class GradeBook.

ClassGradeBook also has one method—displayMessage (lines 7–10). Recall that main is a special method that’s always called automatically by the Java Virtual Machine (JVM) when you execute an application. Most methods do not get called automatically . As you’ll soon see, you must call method displayMessage explicitly to tell it to perform its task.



The method declaration begins with keyword public to indicate that the method is "available to the public"—it can be called from methods of other classes.
Next is the method’s return type, which specifies the type of data the method returns to its caller after performing its task. The return type void indicates that this method will perform a task but will not return (i.e., give back) any information to its calling method. You’ve used methods that return information.


1

2 // Creating a GradeBook object and calling its displayMessage method.

3

4 public class GradeBookTest

5 {

6 // main method begins program execution

7 public static void main( String[] args )

8 {

9 // create a GradeBook object and assign it to myGradeBook

10 GradeBook myGradeBook = new GradeBook();

11

12 // call myGradeBook's displayMessage method

13 myGradeBook.displayMessage();

14 } // end main

15 } // end class GradeBookTest

using myGradeBook followed by a dot separator (.), the method name displayMessage and an empty set of parentheses. This call causes the displayMessage method to perform its task.

For any questions, leave it in comments. thank you.

What we gonna do next is explain how to declare a method with a parameter.

Friday, August 28, 2015

Welcome to Java


The world’s most widely used computer programming language. You’re already familiar with the powerful tasks computers perform. Using this textbook, you’ll write instructions commanding computers to perform those kinds of tasks.

Software (i.e., the instructions you write) controls hardware (i.e., computers). You’ll learn object-oriented programming—today’s key programming methodology. You’ll create and work with many software objects in this text.

Java is the preferred language for meeting many organizations’ enterprise programming needs. Java has also become the language of choice for implementing Internet-based applications and software for devices that communicate over a network.
 
In use today are more than a billion general-purpose computers and billions more Java-enabled cell phones, smartphones and handheld devices (such as tablet computers).
 
According to a study by eMarketer, the number of mobile Internet users will reach approximately 134 million by 2013.1 Other studies have projected smartphone sales to surpass personal computer sales in 20112 and tablet sales to account for over 20% of all personal computer sales by 2015.3 By 2014, the smartphone applications market is expected to exceed $40 billion,4 which is creating significant opportunities for programming mobile applications.
                                       from Jave How to program book

Craig Dennis
writes on November 5, 2014

Eight Reasons You Should Learn Java:-

1. Lots of information

Due to how long Java has been around, almost any question you can imagine has already been asked, answered, indexed, and democratically perfected through upvotes on the Internet. It is seriously hard to stump a search engine with a Java coding problem.

2. An incredible toolset

Java has a very rich API, and an incredible supporting open source ecosystem. There are tools upon tools for just about everything you would like to do. There’s also an amazing community driven process that ensures growth in the right direction

3. Software that leads by example

Java is an Object Oriented language. It internally embraces best practices of object oriented design and strongly suggests that you learn and follow them. It also heavily promotes correct usage and many of the documented Design Patterns use Java as the language de facto. Understanding design patterns can lead to much more maintainable code.

4. Killer editors

The IDEs available for Java will blow your mind. Due to its strong typing, you’ll not only be notified immediately of errors, but you’ll also be given suggestions that will refactor and reformat your code with clear explanations and extreme ease. After using them, most people wonder how they ever coded before.

5. Omnipresence

Java is running just about everywhere you can imagine. It’s usually where most large applications end up due to its scalability, stability, and maintainability. There’s also currently a gigantic push in the Java community to be the leader of the IoT (Internet of Things). And it’s coming. Very fast. There’ll be a time in the near future when your alarm clock will automatically start brewing your coffee pot, and it’ll most likely be Java doing that.

6. Lots of available jobs

There are tons of open positions waiting for you due to Java’s widespread reach. Many different sectors embrace the language, and you can be pretty certain you’ll land a job in just about any job market you’d like.

7. Android adoption

Duke -> Android
All Android Apps are written in Java. By taking our Android Development track, you can publish that app you’ve always dreamed of building.

8. Ease of learning

Java is a verbose language, which at first can seem daunting. However, after learning the basics you’ll find that you can easily grab onto more advanced concepts because the code is very explicit. Plus, there are great courses (wink, wink, nudge, nudge) out there that can ease you into this powerful language.
So what are you waiting for?  It’s time to learn Java.


All rights reserved : this is the original link:
http://blog.teamtreehouse.com/learn-java