Thursday, 16 November 2017

Java tutorial #1 :- shortcut of java to improve coding skills

JAVA Tutorial #1
Hello friends In this Java tutorial i will show you how to reduce coding line in java. Actually i am going to explain it details with simple example of printing a name on the screen. So lets check details.
check this video or follow the step below 


PrintFun():-If you have some basic knowledge about java then you also know that in java to print something on output screen (called console) we use System.out.println() function . But in C language we use printf() function that is quite short. But this fuction only work with file I/O on java and cannot use it for other . 
So Question is How we can use the short name of System.out.println() function ?

here is an answer:-As you know there is not any other function in java which is use in place of System.out.println(). But we can create a userdefine function to do the same task as System.out.println(). So create a simple static type print() function and pass an String arg on it with 'str' variable.Now print this variable inside System.out.println(str); and Now you can call the print() function on each time to print anything on program instead of System.out.println()

Here is a code :- PrintFun.java
---------------------------------------------------------
public class PrintFun 
{
public static void print(String str)
{
System.out.println(str);
}
public static void main(String[] args) 
{
int a=10;
print("Hello TechMate");
print("value of a is: "+a);

}

}
--------------------------------------------------------
Like | Share and Subscribe My channel :-TechMate

No comments:

Post a Comment