Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

local class

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

source : link
hello everyone ,
this is one of the example on the official java tutorials
working good , but i have a doubt , after calling the function validatePhoneNumber , how will this program works
is it going to execute the class directly . ?
and is there any procedure to check any program execution line by line ?
 
Ranch Hand
Posts: 440
Hibernate Eclipse IDE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
if by

is it going to execute the class directly

you meant that it will call the method without any object creation then yes . Notice that the method is static and main also exists inside the same class. Since main is already static and exists in the same class , you can directly call the method ( accessing static methods in static context ) .

is there any procedure to check any program execution line by line


Are you using an IDE ? You can Debug your code with the help of any IDE ( eclipse , intelliJ etc etc ) , it will show you the flow of the execution of the code along with a whole lot of information.
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
doubt clear for ide , but for class i want to say that when we call validatephonenumber() how it uses phonenumber class ?
thanxs
 
Marshal
Posts: 74387
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Programs never use classes. They either use objects made from classes, or methods taken from classes. In this case there is no need for an object; all the information required is passes as a parameter and all the information produced is returned as a return value, so it is a 1368 in the most dubious classification of methods known to modern science. If it ends with 68 you should consider making that method static.
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

this code in the program is the first static block , then it should be execute first then main method <!-- correct me if i am wrong >
if it execute first , then what will be the parameter for phoneNumber1,phoneNumber2 ??
please help
 
Campbell Ritchie
Marshal
Posts: 74387
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What static block?
 
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sparsh khandelwal wrote:
this code in the program is the first static block , then it should be execute first then main method <!-- correct me if i am wrong >
if it execute first , then what will be the parameter for phoneNumber1,phoneNumber2 ??
please help




Do you know the difference between a static initializer and a static method?

Henry
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:

sparsh khandelwal wrote:
this code in the program is the first static block , then it should be execute first then main method <!-- correct me if i am wrong >
if it execute first , then what will be the parameter for phoneNumber1,phoneNumber2 ??
please help




Do you know the difference between a static initializer and a static method?

Henry


i am learning , as static method is one which can be called without making object of the the class .
static initializer ( variable ) is one which have same value throughout the class means you change it at one place and it will be change everywhere in program
 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oopps , its a static function and not a static block thanks
 
Henry Wong
author
Posts: 23909
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sparsh khandelwal wrote:oopps , its a static function and not a static block thanks




Actually, it is a static method and not a static initializer* -- sorry to be anal regarding this, but terminology is very important at this stage, as you will be communicating with other developers at later stages of your learning.

Henry


* To be fair, static block is kinda used interchangeably with static initializer.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic